how a sandbox touches anything else
The three ways out
A sandbox is a virtual machine with a disk and no network device. It has exactly three links to the world, and each is a process on the host that you configure.
Which one do I use?
| way out | use it to | what holds it in |
|---|---|---|
| 1 · Control your tooling → sandbox |
Create a sandbox, run commands, move files, talk to a server inside it, stop it. | Each agent has a socket of its own and sees only its own sandboxes. The sandbox cannot call this API at all. |
| 2 · Network sandbox → internet |
Fetch public things that need no credential: packages, a public repository. | A list of hostnames per sandbox, empty by default. Public addresses only, port 443 only. |
| 3 · Capabilities sandbox → host |
Anything that needs a credential or touches your own systems: a private repository, an API, a tool of yours. | A menu, a grant per agent, and limits on every entry. The credential stays on the host. |
1 · The control API
The broker serves a small HTTP API, /v1, with JSON in and JSON out. This is what your agent's tooling calls. The full reference is SPEC.md.
The socket is the identity
Each agent has one Unix socket, fixed in the broker's config, and only the configured user may connect to it. There is no API key and no Authorization header: the kernel says who is on the other end.
Nothing in a request can move a caller to another agent's sandboxes. Another agent's sandbox answers 404, the same as one that does not exist.
# the broker's config [cap_groups.bots] [agents.mybot] cap_group = "bots" listen = { kind = "unix", path = "/run/sandbox-broker/mybot/api.sock", uid = "mybot" } # your tooling SOCK=/run/sandbox-broker/mybot/api.sock b() { curl -s --unix-socket "$SOCK" "$@"; } b http://broker/v1/status
The calls
| call | what it does |
|---|---|
POST /v1/sandboxes | Create one and boot it. Optional: a network profile, grants, CPUs, memory, disk, a lifetime, persistent, and a source: a public Git URL to clone, or another of your sandboxes to copy. |
GET /v1/sandboxesGET /v1/sandboxes/{name} | Your sandboxes, or one: status, profile, grants, sizes, free disk and memory, when it expires. |
POST …/{name}/commands | Run a command. The answer streams its output, or with detach returns an id at once. |
GET …/commands/{id}GET …/commands/{id}/logsPOST …/commands/{id}/kill | A command's status (optionally waiting for its end), its output from the start or the tail, and a signal. |
PUT …/{name}/filesGET …/{name}/files | Unpack a tar.gz into the sandbox (32 MiB at most), or read one file out. |
POST …/{name}/stream | Upgrade to a raw two-way byte stream to a port or a Unix socket inside the sandbox. |
PUT …/{name}/profilePUT …/{name}/grants | Change the network profile or the capability grants of a running sandbox. |
POST …/{name}/stopPOST …/{name}/resumePOST …/{name}/extendDELETE …/{name} | Stop it (the answer carries the session's CPU time and bytes), boot it again on its kept disk, push its deadline out, or remove it and its disk. |
GET /v1/notices | Long-poll for things that happened without you: a detached command ended, a sandbox was stopped for idling, its network was cut. |
Commands
A command's output streams back as one JSON object per line. The last line is always the exit code or an error; a stream that ends without one broke.
A command outlives its caller. If your tooling times out or crashes, the command runs on and can be listed, read, waited on and killed by its id. With detach, the broker sends a notice when it ends.
Commands run as an ordinary user. "sudo": true runs one as root, which is root in the guest and nothing more.
b -X POST http://broker/v1/sandboxes/sw-mybot-1/commands \
-d '{"command": "npm", "args": ["test"], "timeout_ms": 600000}'
{"stream": "stdout", "data": "…"}
{"stream": "stderr", "data": "…"}
{"exit_code": 0, "duration_ms": 48213}
b -X POST http://broker/v1/sandboxes/sw-mybot-1/commands \
-d '{"command": "cargo", "args": ["build"], "detach": true}'
{"id": "c-2", "status": "running"}
b 'http://broker/v1/sandboxes/sw-mybot-1/commands/c-2?wait=20'
b 'http://broker/v1/sandboxes/sw-mybot-1/commands/c-2/logs?tail_bytes=4096'
A stream into the sandbox
If the agent starts a server in its sandbox, such as a dev server, a language server or an MCP server, your tooling can open a byte stream straight to its port or its Unix socket. Nothing is exposed on any network to do it.
POST /v1/sandboxes/sw-mybot-1/stream?port=3000 HTTP/1.1 Connection: Upgrade Upgrade: sb-stream HTTP/1.1 101 Switching Protocols … raw bytes, both ways …
Lifetimes, and what is cleaned up for you
Every session has a deadline, and you can extend it up to a maximum set per agent. A sandbox that sits idle is stopped. One that is not persistent is deleted when it stops; a persistent one keeps its disk until you delete it, and can be resumed.
A sweep runs every two minutes and settles whatever a crash or a lost reply left behind, so a caller that retries cannot pile up orphans.
Budgets
Agents belong to a cap group. A group can cap how many sandboxes run at once and how much CPU time they use per day and per month. Each agent has ceilings on CPUs, memory, disk and the number of kept workspaces.
Sizes and budgets over the cap are refused with broker_quota and say which cap. Durations are clamped, and the answer shows the value in force.
Errors you can branch on
Every refusal has the same shape and a code from a closed list: broker_not_running, broker_quota, broker_widen, broker_too_large and so on. The internals behind the API never leak through it.
HTTP/1.1 409 Conflict
{"error": {"code": "broker_not_running",
"message": "…"}}
2 · Network by hostname
There is no network card in the guest. Programs in it use the usual proxy settings, which point at a small bridge on the guest's loopback. The bridge forwards each connection, by name, to a proxy process on the host that belongs to this one sandbox. Whether the name is allowed is the host's decision alone.
Profiles
A profile is a named list of hostnames, written per agent in the broker's config. deny-all always exists and allows nothing, DNS included. A sandbox is created under one profile and can be moved to another while it runs.
When a profile changes, open connections the new list does not allow are closed, not left to drain.
[agents.mybot]
switch = "own-profiles"
profiles.github = { allow = ["github.com"] }
profiles.deps-npm = { allow = ["registry.npmjs.org"] }
profiles.deps-py = { allow = ["pypi.org", "files.pythonhosted.org"] }
profiles.deps-rust = { allow = ["index.crates.io", "static.crates.io"] }
What the proxy enforces
| rule | meaning |
|---|---|
| By name | A connection is asked for by hostname and matched against the profile. The guest never resolves a name itself. |
| Public addresses only | Every address a name resolves to is checked. A name that points at your LAN, the host itself or any private range is refused, even if it is on the list. |
| Port 443 only | Plain HTTP is not carried. The bridge answers it 405. |
| Which way it may change | Per agent. tighten-only: a sandbox's list can only shrink. own-profiles: it may switch among the agent's named profiles, in either direction. Neither can move a running sandbox to a profile that allows every name. |
| Not left open | A sandbox that has been off deny-all for 15 minutes is switched back, with a notice five minutes before. A profile may set a longer limit, open_secs. |
The pattern: fetch, tighten, run
Dependencies need the network and untrusted code should not have it. So do them in that order, in the same sandbox.
The proxy counts bytes in and out per session, and which names were asked for, for the private audit. It does not throttle: there is no bandwidth limit yet.
b -X POST http://broker/v1/sandboxes -d '{"profile": "deps-npm"}'
# … npm ci …
b -X PUT http://broker/v1/sandboxes/sw-mybot-1/profile \
-d '{"profile": "deny-all"}'
# … now run what the model wrote …
deny-all.3 · Capabilities
A sandbox with grants has a second socket, $SB_CAP_SOCK. Through it the code in the sandbox asks the host to do a named thing: clone a private repository, push a branch under a prefix, call one route of an API, or call a tool you wrote. The host checks the request, applies its limits, and carries it out with a credential the sandbox never sees.
curl --unix-socket "$SB_CAP_SOCK" http://cap/_grants git clone cap::github/acme/web git push origin HEAD:bot/fix-123
This is the way out that makes a sandbox useful for real work, and it has a page of its own.
Inside the sandbox
The machine
Ubuntu 24.04 with git, Node, Python and Rust. CPUs, memory and disk are what the create asked for, within the agent's ceilings.
The workspace
A disk of its own, mounted at /work; the working directory is /work/sandbox. Packages the agent installs and the caches of cargo, npm and pip live on it, so they last as long as the workspace does.
No walls inside
The sandbox user has passwordless sudo. That is deliberate: the boundary is the virtual machine, not anything in it. Do not rely on file permissions inside a sandbox to keep two things apart.
What goes in is checked
By default, uploads, command arguments and environment variables that contain something shaped like a well-known credential are refused, so a token is not placed in a sandbox by mistake. An operator can list environment variable names per agent, secret_env_allow, whose values a command may carry. Everything in that sandbox can read such a value and it can leave by any open profile, so its protection is the key's own spend limit and revocation.
What is kept about it
Each command's arguments, each file moved and each profile change go to a private audit on the host. Command output and file contents do not. Nothing of a sandbox's content is written to the host's logs.
Your own process at boot
An agent can be configured with a read-only bundle and an entry point that is started in every one of its sandboxes at boot: a place for your harness's in-sandbox half.