feat: integrate Tensorlake MicroVM sandbox as a new sandbox backend#1
Open
feat: integrate Tensorlake MicroVM sandbox as a new sandbox backend#1
Conversation
Tensorlake provides Firecracker MicroVM sandboxes with sub-second startup,
durable filesystem state, auto suspend/resume, and live migration. This
commit adds Tensorlake as a first-class sandbox provider alongside the
existing docker, podman, and sandbox-exec backends.
## What changed
### packages/core/src/config/config.ts
- Added 'tensorlake' to the SandboxConfig.command union type
### packages/cli/src/config/sandboxConfig.ts
- Added 'tensorlake' to VALID_SANDBOX_COMMANDS
- Detection uses the 'tl' CLI binary (Tensorlake's own binary name)
- Tensorlake sandboxes do not require a container image URI; they use
the Tensorlake cloud platform to provision MicroVMs. A 'tensorlake'
placeholder is returned as the image field.
- Updated auto-detection order: sandbox-exec → docker → podman → tensorlake
- Updated error message to mention tensorlake as an option
### packages/cli/src/utils/sandbox.ts
- Added start_tensorlake_sandbox() function implementing the full sandbox
lifecycle:
1. Creates a Tensorlake MicroVM via 'tl sbx new' (with --json fallback)
2. Copies the current workspace into the sandbox
3. Installs Node.js + blackbox CLI inside the sandbox (best-effort)
4. Forwards all relevant API keys and environment variables
5. Executes 'blackbox' with the original CLI arguments inside the sandbox
6. Streams stdout/stderr back to the host terminal via stdio: 'inherit'
7. Terminates the sandbox on process exit, SIGINT, and SIGTERM
- Added TENSORLAKE_API_KEY forwarding to docker/podman sandbox paths
### packages/cli/src/config/sandboxConfig.test.ts (new)
- 8 unit tests covering the Tensorlake loadSandboxConfig path:
- GEMINI_SANDBOX=tensorlake with tl installed → returns tensorlake config
- GEMINI_SANDBOX=tensorlake without tl → throws FatalSandboxError
- sandbox=tensorlake via CLI argv → returns tensorlake config
- sandbox via settings.tools.sandbox → returns tensorlake config
- GEMINI_SANDBOX_IMAGE is ignored for tensorlake (cloud-managed)
- SANDBOX env var set → returns undefined (already inside sandbox)
- docker takes priority over tensorlake in auto-detection
- tensorlake auto-selected when only tl is available
## Usage
Set GEMINI_SANDBOX=tensorlake and TENSORLAKE_API_KEY before running:
export GEMINI_SANDBOX=tensorlake
export TENSORLAKE_API_KEY=your_api_key
blackbox
Or pass via CLI flag:
TENSORLAKE_API_KEY=... blackbox --sandbox tensorlake
Optional tuning:
TENSORLAKE_CPUS=4 # vCPUs (default: 2)
TENSORLAKE_MEMORY=8192 # Memory MB (default: 4096)
TENSORLAKE_TIMEOUT=7200 # Timeout seconds (default: 3600)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add Tensorlake as a first-class sandbox provider, giving users access to Firecracker MicroVM-backed sandboxes with sub-second startup, durable filesystem state, and automatic lifecycle management.
Context
The blackbox CLI already supports sandboxing via
docker,podman, and macOSsandbox-exec. Tensorlake offers a complementary cloud-based option using Firecracker MicroVMs — lightweight, isolated, and suitable for CI/CD or environments where Docker is unavailable. This PR wires Tensorlake into the existing sandbox abstraction with minimal surface area changes so the rest of the CLI is unaffected.Changes
SandboxConfigtype — extended thecommandunion inpackages/coreto include'tensorlake'sandboxConfig.ts— added'tensorlake'to the valid commands list; maps to thetlCLI binary for availability checking; skips the container image URI requirement (Tensorlake provisions its own MicroVMs); addedtensorlakeas the last fallback in the auto-detection chain (sandbox-exec → docker → podman → tensorlake)sandbox.ts— implementedstart_tensorlake_sandbox()which:tl sbx new(JSON output with text-parse fallback)tl sbx cpGEMINI_API_KEY,TENSORLAKE_API_KEY,BLACKBOX_API_KEY, etc.)blackboxinside the sandbox with the original CLI arguments, streaming stdio back to the hostexit,SIGINT, andSIGTERMTENSORLAKE_API_KEYforwarding also added to the docker/podman--envblock for completenesssandboxConfig.test.ts(new) — 8 unit tests covering the full Tensorlake config-loading pathKey Implementation Details
Tensorlake sandboxes are identified by an opaque
sbx-*ID returned by thetlCLI. TheSANDBOXenv var is set totensorlake-<sbx-id>inside the MicroVM so the CLI's existing guard against double-sandboxing continues to work. Thetlbinary is the indicator used for availability detection rather thantensorlakebecause that is the actual installed binary name.Use Cases
Testing
Unit tests (no Tensorlake account needed)
cd packages/cli ../../node_modules/.bin/vitest run src/config/sandboxConfig.test.tsAll 8 tests should pass covering: explicit env var, missing
tlbinary error, CLI argv, settings file, image override ignored, already-inside-sandbox guard, auto-detection priority, and tl-only auto-detection.Integration test (requires
tlCLI +TENSORLAKE_API_KEY)Verify via
tl sbx listthat a sandbox was created and then terminated after the command exits.TypeScript type check
No new errors in sandbox or tensorlake files.