sandbox-cli

module
v0.0.0-...-f03fdf5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: MIT

README

sandbox-cli

Isolated microVM sandboxes for any command — on your Mac, on a Linux machine you control, or in the cloud, behind one API. Coding agents are a layer on top (sandbox-cli agent), not a requirement.

Every sandbox is a VM with its own kernel. A sandbox is not built around your repository: every process starts in the sandbox user's home, /sandbox/home, and code gets in the way it gets into any machine, by git clone inside the sandbox or through the files API. None of your files are mounted into the guest, and nothing comes back to your machine except an agent's saved login. Egress is open by default; ask for an allowlist (--network allowlist, or the prod profile) and it is enforced outside the guest, where the agent cannot reach it, with the agent's own API always on it.

  sandbox VM  (its own kernel; processes start in /sandbox/home)
  code:     git clone inside the sandbox, or the files API; volumes keep data between runs
  network:  open by default; or an allowlist of names, enforced on the host (prod: always)
  logins:   copied in and out per run, never a mounted host directory

This is the rewrite. The beta.15 tool ran agents in docker containers; this one runs microVMs, and it drops docker, podman and Windows. See CHANGELOG.md and docs/rewrite/PLAN.md.

Three ways to run it

Where Isolation Guide
Local your Mac (macOS 26+, arm64) a VM of the native container runtime docs/local-macos.md
Self-hosted a Linux machine with KVM, or many behind one gateway Firecracker microVMs, egress enforced on the host docs/self-hosting.md, docs/fleet.md
Cloud hosted the same as self-hosted (coming)

sandboxd serves the API on each machine. The CLI and the SDKs are clients; they cannot tell which of the three they are talking to, beyond what sandbox-cli doctor reports. sandbox-gateway serves the same API in front of many machines, with a key per user, sandboxes only their owner can see, and SSH on one port (docs/fleet.md).

On a Linux server, give sandboxes a disk of their own before installing: images, sandboxes' disks, snapshots and volumes all live under /var/lib/sandboxd, and mounted there they fill that disk and not /. With --keep-sandboxes, sandboxd restarts and upgrades without stopping the sandboxes it runs. The install, the disk, the production checklist and upgrades are in docs/self-hosting.md; the /setup page of the website walks through each path step by step.

Use it

sandbox-cli context add box https://sandbox.example.internal:7443 --token-file ~/box.token --ca ~/box-ca.pem
sandbox-cli context use box          # or stay on "local"

sandbox-cli run -- uname -a         # a fresh VM; its exit code is yours
sandbox-cli run -- sh -c 'git clone https://github.com/you/app && cd app && npm test'   # needs a network that reaches github.com
sandbox-cli run --network none -- make
sandbox-cli run --keep --name dev -- bash
sandbox-cli run --detach --name dev -- sleep infinity
sandbox-cli shell dev               # a shell in a running sandbox; exit leaves it running
sandbox-cli exec dev -- git clone https://github.com/you/app   # one command in it; its exit code is yours
sandbox-cli list · logs ID · attach ID · kill ID
sandbox-cli snapshot · snapshot-ls · snapshot-rm · suspend · resume · tunnel
sandbox-cli events ID                # what the sandbox was asked to do, and how it ended
sandbox-cli volume create cache; sandbox-cli run --volume cache:/sandbox/home/.cache -- npm ci
sandbox-cli run --label team=infra -- make; sandbox-cli list --label team=infra
sandbox-cli run --template large -- make            # a size by name; template ls lists them
sandbox-cli update dev --name api --idle 2h         # rename, relabel, retime or re-network a live sandbox
sandbox-cli image pull IMAGE · image ls · image rm IMAGE   # install an image before its first sandbox waits for it

A sandbox starts from the server's default image, which has git, Node, Python and four agents, unless you name another: --image python:3.13-slim, or any public Linux image (ghcr.io/owner/name:tag, name@sha256:…). It is pulled the first time a sandbox asks for it; a private image cannot be pulled. Which names work and what an image needs: docs/self-hosting.md.

Work done in a sandbox stays there. To keep it, push it from inside (a commit made in a sandbox carries a neutral sandbox identity), read it out through the files API, or write it to a volume, which outlives the VM.

Through a gateway

A gateway puts many sandboxd nodes behind one address, with a user for every API key and one SSH port for every sandbox. The CLI uses it like any other context:

sandbox-cli context add fleet https://gateway.example.internal --token-file ~/fleet.key
sandbox-cli context use fleet
sandbox-cli whoami                   # user, tenant, scopes and key id
sandbox-cli run --keep --name demo -- sleep infinity
sandbox-cli ssh demo                 # registers ~/.ssh/id_ed25519.pub, pins the host key, runs ssh
sandbox-cli ssh demo -- uname -a

sandbox-cli ssh-key add              # or register a key yourself; then plain ssh works:
ssh demo@gateway.example.internal -p 2222
sandbox-cli ssh-key list · ssh-key rm ID

sandbox-cli ssh-access demo --ttl 15m   # a short-lived `ssh TOKEN@gateway …` line, no key needed

The token in an ssh-access line is the whole credential until it expires; hand it only to whoever should have that access. Every SSH login needs an active API key with the sandbox:ssh scope, and revoking it closes open sessions too (docs/operations.md; all of SSH is in docs/ssh.md). Against a plain sandboxd, sandbox-cli ssh opens the session through the API instead, since a sandboxd has no SSH server.

Agents and jobs on a fleet

A gateway also runs work after you have gone. A job is a command, or an agent and a prompt, run in a fresh sandbox per run: the gateway places it, starts it, waits with a timeout, keeps its output (1 MiB per stream) and the files you name (8 MiB each), terminates the sandbox, and retries a run that failed. prompts makes a batch, one run per prompt; parallelism bounds how many run at once. A run that does not fit the tenant's quota waits for room.

sandbox-cli secret set ANTHROPIC_API_KEY < key.txt      # sealed on the gateway, never shown again
sandbox-cli agent-run claude "fix the failing test" --secret ANTHROPIC_API_KEY --wait

cat > job.yaml <<'YAML'
agent: claude
prompts: ["review internal/api", "review internal/gateway"]
parallelism: 2
retries: 1
timeout_secs: 1800
secrets: [ANTHROPIC_API_KEY]
keep: {files: [/sandbox/home/review.md]}
notify: https://hooks.example.com/sandbox    # POSTed {job, run, state}; never output
YAML
sandbox-cli job run -f job.yaml
sandbox-cli job ls · job get ID · job output ID 0 [--file PATH] · job cancel ID

An agent runs in its verified headless mode (claude, codex, gemini, opencode, cline). Your saved login does not come along — the CLI's run copies it in from your machine, and a job has none — so the agent authenticates with an API key you keep as a secret: ANTHROPIC_API_KEY for claude, OPENAI_API_KEY for codex, GEMINI_API_KEY for gemini, the provider's for opencode and cline. The agent must be in the image or installable from it. A secret goes into a run's environment by name, only for jobs that name it; the API never returns it. Secrets need the gateway started with --secrets-key-file (32 random bytes, mode 0600), and setting one needs a key with the secrets:write scope. A finished job is kept for a day (--job-retention). A restarted gateway picks its jobs up again: a running command is followed where it runs. Jobs, batches, secrets and notify webhooks are in docs/jobs.md; services, which keep a count of sandboxes running, in docs/services.md.

Coding agents

sandbox-cli agent <name> is run with a coding agent's conveniences on top: its login is restored into the sandbox and saved again afterwards, and its own environment variables are forwarded when set.

sandbox-cli agent ls                                  # the agents, and whose login is saved (here, or on the gateway)
sandbox-cli agent claude                              # Claude Code in a fresh VM
sandbox-cli agent claude --network none -- --resume   # sandbox flags first, then the agent's
sandbox-cli agent codex --detach -- exec "fix the failing test"

Agents: claude, codex, gemini, opencode and cline, which can also run unattended, and copilot, cursor, devin, goose, kilocode, openhands and qwen.

When a provider is down, a run can fall through to another agent:

sandbox-cli agent claude --fallback codex -p "fix the failing test"

Each provider is probed before a sandbox is made for it, and one that is down is skipped for the next. A run that started is never retried with another agent: it may have done work, and that work must not be done twice. Put routing: [claude, codex] in ~/.config/sandbox/config.yaml to make a chain the default; a project's .sandbox.yaml cannot set it.

With several agents going, sandbox-cli agent state says which one needs you. It reports working, blocked (quiet at a terminal, so waiting for an answer), idle, done or failed. It decides from the agent's process and its conversation, never from what the agent wrote. agent wait blocks until an agent gets to one of the states you name:

sandbox-cli agent state
sandbox-cli agent wait fix-auth --state blocked --state done --state failed --timeout 30m

Studio

sandbox-cli studio          # prints http://127.0.0.1:7080/#token=…

The same sandboxes in a browser: launch a command or an agent, use its terminal, watch its output, files and audit events. Studio is served by sandbox-cli itself on a loopback port, needs the token it prints, and talks to the current context's sandboxd without handing that sandboxd's token to the browser. See docs/studio.md.

Build

make build      # bin/sandbox-cli, bin/sandboxd, bin/sandbox-guestd (linux, for the guest)
make test       # unit tests and the API conformance suite against an in-memory backend

The microVM tests need /dev/kvm; see AGENTS.md and docs/testing/end-to-end.md.

Documents

Directories

Path Synopsis
_old
cmd/gen-contract command
Command gen-contract writes the TypeScript and Swift mirrors of the Studio API's wire shapes from the Go types that define them.
Command gen-contract writes the TypeScript and Swift mirrors of the Studio API's wire shapes from the Go types that define them.
cmd/sandbox-cli command
Command sandbox runs AI coding agents and arbitrary commands inside a disposable, isolated Docker container.
Command sandbox runs AI coding agents and arbitrary commands inside a disposable, isolated Docker container.
cmd/sandbox-studio-api command
Command sandbox-studio-api runs the local HTTP control plane for sandbox-cli — see internal/studioapi and docs/studio-api/README.md.
Command sandbox-studio-api runs the local HTTP control plane for sandbox-cli — see internal/studioapi and docs/studio-api/README.md.
internal/agentctx
Package agentctx knows where each agent keeps its conversation transcripts, and remembers what it found.
Package agentctx knows where each agent keeps its conversation transcripts, and remembers what it found.
internal/cli
Package cli wires the cobra command tree for the `sandbox-cli` binary.
Package cli wires the cobra command tree for the `sandbox-cli` binary.
internal/contract
Package contract generates the TypeScript mirror of the Studio API's wire shapes from the Go types that define them.
Package contract generates the TypeScript mirror of the Studio API's wire shapes from the Go types that define them.
internal/detect
Package detect decides how an agent is doing, from evidence rather than from prose.
Package detect decides how an agent is doing, from evidence rather than from prose.
internal/doctor
Package doctor asks whether a host can deliver what a profile promises.
Package doctor asks whether a host can deliver what a profile promises.
internal/history
Package history is a queryable index over the audit log.
Package history is a queryable index over the audit log.
internal/image
Package image lazily builds the embedded sandbox base image on first use.
Package image lazily builds the embedded sandbox base image on first use.
internal/metrics
Package metrics renders a live, one-line resource gauge (memory, CPU, elapsed time, and the workspace's git branch) for a running sandbox container.
Package metrics renders a live, one-line resource gauge (memory, CPU, elapsed time, and the workspace's git branch) for a running sandbox container.
internal/netpolicy
Package netpolicy is a seam for network egress control.
Package netpolicy is a seam for network egress control.
internal/protocol
Package protocol is the wire format between sandbox-cli's clients — the CLI, Studio, an SDK — and the session server that owns the catalog of running sandboxes.
Package protocol is the wire format between sandbox-cli's clients — the CLI, Studio, an SDK — and the session server that owns the catalog of running sandboxes.
internal/rescue
Package rescue is the crash safety net for the user's work.
Package rescue is the crash safety net for the user's work.
internal/runtime
Package runtime executes a normalized RunSpec inside a container backend.
Package runtime executes a normalized RunSpec inside a container backend.
internal/sandbox
Package sandbox composes config, image building, and the runtime backend into a single Session that resolves a request and runs it in an isolated container.
Package sandbox composes config, image building, and the runtime backend into a single Session that resolves a request and runs it in an isolated container.
internal/session
Package session owns the catalog of sandboxes for one repository: which worktrees exist, which containers are in them, and how each is doing.
Package session owns the catalog of sandboxes for one repository: which worktrees exist, which containers are in them, and how each is doing.
internal/studioapi
Package studioapi is the HTTP control plane for sandbox-cli: a local API server a frontend ("Sandbox Studio") talks to instead of shelling out to the CLI itself.
Package studioapi is the HTTP control plane for sandbox-cli: a local API server a frontend ("Sandbox Studio") talks to instead of shelling out to the CLI itself.
internal/worktree
Package worktree makes "one sandbox per git branch" a one-liner.
Package worktree makes "one sandbox per git branch" a one-liner.
cmd
sandbox-cli command
Command sandbox-cli runs AI coding agents and arbitrary commands inside a disposable, isolated sandbox.
Command sandbox-cli runs AI coding agents and arbitrary commands inside a disposable, isolated sandbox.
sandbox-gateway command
Command sandbox-gateway is one address in front of many sandboxd nodes (package gateway).
Command sandbox-gateway is one address in front of many sandboxd nodes (package gateway).
sandbox-guestd command
Command sandbox-guestd is the guest agent: the only thing inside a sandbox VM that the host talks to (internal/guestproto).
Command sandbox-guestd is the guest agent: the only thing inside a sandbox VM that the host talks to (internal/guestproto).
sandboxd command
Command sandboxd serves Sandbox API v1 (docs/api/v1.md) for one machine.
Command sandboxd serves Sandbox API v1 (docs/api/v1.md) for one machine.
internal
agentctx
Package agentctx reads agents' conversation transcripts.
Package agentctx reads agents' conversation transcripts.
agenthome
Package agenthome is what an agent finds in its home directory in a sandbox: its saved login, copied in when a run starts and back out when it ends, and the tools volume an image without the agent installs it into.
Package agenthome is what an agent finds in its home directory in a sandbox: its saved login, copied in when a run starts and back out when it ends, and the tools volume an image without the agent installs it into.
agents
Package agents describes the AI coding agents sandbox-cli knows how to start, as data rather than as code duplicated per subcommand.
Package agents describes the AI coding agents sandbox-cli knows how to start, as data rather than as code duplicated per subcommand.
agentstate
Package agentstate says how an agent is doing — working, waiting for you, idle, finished — from evidence rather than from prose.
Package agentstate says how an agent is doing — working, waiting for you, idle, finished — from evidence rather than from prose.
api
Package api is the Sandbox API v1: its wire types, a Go client, and — in api/conformance — the suite that defines what every endpoint must do.
Package api is the Sandbox API v1: its wire types, a Go client, and — in api/conformance — the suite that defines what every endpoint must do.
api/conformance
Package conformance is the definition of "the same API in every mode".
Package conformance is the definition of "the same API in every mode".
audit
Package audit is the server's event log: what each sandbox was asked to do, and what happened to it.
Package audit is the server's event log: what each sandbox was asked to do, and what happened to it.
backend
Package backend is the seam between what a sandbox should be and the thing that makes one: a VM under the macOS `container` runtime, a Firecracker microVM, or the in-memory fake.
Package backend is the seam between what a sandbox should be and the thing that makes one: a VM under the macOS `container` runtime, a Firecracker microVM, or the in-memory fake.
backend/fake
Package fake is an in-memory backend, so the API, the policy and the server can be tested — and the conformance suite run — with no VM and no daemon.
Package fake is an in-memory backend, so the API, the policy and the server can be tested — and the conformance suite run — with no VM and no daemon.
backend/firecracker
Package firecracker is the Linux backend, for self-hosted and cloud: every sandbox is a Firecracker microVM.
Package firecracker is the Linux backend, for self-hosted and cloud: every sandbox is a Firecracker microVM.
backend/macos
Package macos is the local backend: on a Mac (macOS 26+, arm64) each sandbox is a lightweight VM run by the native `container` runtime — its own kernel, one per sandbox.
Package macos is the local backend: on a Mac (macOS 26+, arm64) each sandbox is a lightweight VM run by the native `container` runtime — its own kernel, one per sandbox.
cli
Package cli is cobra wiring and nothing else.
Package cli is cobra wiring and nothing else.
creds
Package creds is the credential broker.
Package creds is the credential broker.
egressproxy
Package egressproxy enforces the egress allowlist by **name** rather than by address.
Package egressproxy enforces the egress allowlist by **name** rather than by address.
gateway
Package gateway is sandbox-gateway: one address in front of any number of sandboxd nodes (docs/roadmap/task-7-fleet-gateway.md).
Package gateway is sandbox-gateway: one address in front of any number of sandboxd nodes (docs/roadmap/task-7-fleet-gateway.md).
githard
Package githard neutralises the parts of a git repository's own configuration that make git run commands.
Package githard neutralises the parts of a git repository's own configuration that make git run commands.
guestproto
Package guestproto is how the host talks to sandbox-guestd inside a VM — the only way it does.
Package guestproto is how the host talks to sandbox-guestd inside a VM — the only way it does.
hostpath
Package hostpath holds the refusals that apply to every host path sandboxd reads or mounts: never the filesystem root, never the user's home, never an ancestor of it — compared by identity, not by string.
Package hostpath holds the refusals that apply to every host path sandboxd reads or mounts: never the filesystem root, never the user's home, never an ancestor of it — compared by identity, not by string.
image
Package image turns an OCI image into what a backend boots: on Linux, a read-only ext4 root disk for Firecracker.
Package image turns an OCI image into what a backend boots: on Linux, a read-only ext4 root disk for Firecracker.
metrics
Package metrics writes the Prometheus text exposition format by hand, for sandboxd's and sandbox-gateway's GET /metrics.
Package metrics writes the Prometheus text exposition format by hand, for sandboxd's and sandbox-gateway's GET /metrics.
policy
Package policy defines the sandbox configuration schema and its layered discovery/merge rules: built-in defaults < user config < project config < flags.
Package policy defines the sandbox configuration schema and its layered discovery/merge rules: built-in defaults < user config < project config < flags.
publicnet
Package publicnet keeps a connection the host makes on a client's behalf — to a URL the client named — on the public internet.
Package publicnet keeps a connection the host makes on a client's behalf — to a URL the client named — on the public internet.
routing
Package routing decides which agent a run actually uses when the first choice is unavailable.
Package routing decides which agent a run actually uses when the first choice is unavailable.
server
Package server serves Sandbox API v1 (docs/api/v1.md) for one machine, over whichever backend that machine has.
Package server serves Sandbox API v1 (docs/api/v1.md) for one machine, over whichever backend that machine has.
spec
Package spec turns an API request into a fully resolved backend.Spec, against the server's policy, and refuses what the policy does not permit.
Package spec turns an API request into a fully resolved backend.Spec, against the server's policy, and refuses what the policy does not permit.
state
Package state records what no later command could otherwise recover about a sandbox: its repository, branch, agent and base.
Package state records what no later command could otherwise recover about a sandbox: its repository, branch, agent and base.
studio
Package studio is the local server behind `sandbox-cli studio`: it serves the browser UI and a small API, and holds the one thing the browser must not — the token of the sandboxd the current context points at.
Package studio is the local server behind `sandbox-cli studio`: it serves the browser UI and a small API, and holds the one thing the browser must not — the token of the sandboxd the current context points at.
termsafe
Package termsafe strips the characters a terminal reads as commands from strings that came from somewhere untrusted.
Package termsafe strips the characters a terminal reads as commands from strings that came from somewhere untrusted.
version
Package version holds build metadata and the base image tag.
Package version holds build metadata and the base image tag.
vsock
Package vsock is the host<->guest socket: listening on a vsock port inside a Linux guest, and dialling one from the host through Firecracker's unix-socket bridge.
Package vsock is the host<->guest socket: listening on a vsock port inside a Linux guest, and dialling one from the host through Firecracker's unix-socket bridge.
scripts
m3/m3tool command
Command m3tool is the helper for the M3 measurements (scripts/m3/README.md).
Command m3tool is the helper for the M3 measurements (scripts/m3/README.md).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL