A sandbox is a Firecracker microVM with its own kernel, claimed from a pool of microVMs that were restored from a snapshot ahead of time. Your request does not wait for a boot. Use one to run code an agent wrote, to give an agent a computer of its own, or to run the agent itself on the node, next to the model the node serves.

Create a sandbox

bash
curl -s https://beta-api.b3os.org/v1/sandboxes \ -H "Authorization: Bearer $B3OS_API_KEY" \ -H "Content-Type: application/json" \ -d '{"template": "base", "vcpu": 2, "memory_mib": 2048, "timeout_s": 900}'

The sandbox comes back running. Its timing shows the claim.

FieldDefaultMeaning
templatebaseThe template to start from, by name or tpl_ ID
snapshotnoneRestore one of your snapshots instead of a template
vcpu1Virtual CPUs, up to your plan's maximum (2 in the beta)
memory_mib512Memory in MiB, up to 2048 in the beta
disk_gibthe template'sDisk size
timeout_s300Lifetime in seconds from creation or from the last extension; the beta allows up to an hour
on_idlestopWhat happens at expires_at: stop destroys the sandbox, pause keeps it for a later resume
envnoneEnvironment variables, returned as given
secretsnoneEnvironment variables never returned or logged: a value, or a field of a vault connection
portsnoneUp to 8 ports to reach from outside; see ports
apino accessWhat code inside may call on B3OS; see agents in sandboxes
egresspublicWhere the sandbox's traffic may go: public, allowlist or deny

Templates

GET /v1/sandboxes/templates lists the templates with their contents and default sizes:

TemplateContents
baseUbuntu 24.04 with Python 3.12, Node 24 and git
code-interpreterbase plus a Jupyter kernel for run_code, in Python and JavaScript
agentbase plus the Claude Agent SDK, the OpenAI Agents SDK and LangGraph

Lifecycle

mermaid
stateDiagram-v2 [*] --> running: create running --> paused: pause paused --> running: resume running --> stopped: delete or timeout paused --> stopped: delete or timeout running --> failed: microVM crashed
  • Extend with POST /v1/sandboxes/{sandbox_id}/timeout and a new timeout_s, counted from now. It works on running and paused sandboxes.
  • Pause freezes the vCPUs and keeps memory and disk on the node; resume continues exactly where it stopped, with the guest clock corrected. See snapshots and pausing.
  • Delete stops the sandbox and destroys its memory and disk. It returns the stopped sandbox with its final usage; snapshots taken from it are kept.
  • A stopped sandbox cannot be restarted. Calls that need a running one fail with sandbox_not_running, whose current_status says why.

Each sandbox starts with a fresh identity (new entropy, machine ID and clock), even when many come from one snapshot, so no two sandboxes share random state.

Networking

A sandbox has no network card. Its outbound traffic leaves through the node's egress guard, which allows the public internet by default and never the node's network, loopback or cloud metadata addresses. Narrow it per sandbox:

json
{ "template": "base", "egress": { "mode": "allowlist", "allow": ["github.com", "*.githubusercontent.com"] } }

deny blocks outbound traffic entirely. Inbound traffic reaches a sandbox only through its declared ports.

Inside the sandbox

The environment includes:

VariableValue
B3OS_API_URLhttp://127.0.0.1:7700, the B3OS API without a key
B3OS_SANDBOX_IDThe sandbox's sbx_ ID
B3OS_PROJECTYour project ID
B3OS_PORT_BASE_PATH/sbx/<host_id>, the fixed start of every port preview path

The B3OS SDK and CLI detect B3OS_API_URL and use it on their own.

Billing and scopes

A running sandbox bills sandboxes.vcpu_ms (CPU time it used) and sandboxes.gib_ms (allocated memory times wall time). A paused sandbox bills no CPU time. Whether it bills memory while paused is still being settled for the beta; the sandbox's usage shows what it was charged.

ScopeFor
sandboxes:writeCreate, delete, pause, resume, snapshot and extend sandboxes
sandboxes:runRun commands and code, read and write files, open terminals, read logs, mint port URLs
sandboxes:readList and read sandboxes, snapshots and templates

Guides

Commands, code and files

Exec, streaming output, background processes, run_code, files and a terminal.

Learn More
Ports and previews

Reach a server in the sandbox through a signed URL.

Learn More
Snapshots and pausing

Pause and resume, save a sandbox, and start new ones from it.

Learn More
Agents in sandboxes

Grants, the in-sandbox API, secrets from the vault and nested sandboxes.

Learn More

Limits and FAQ lists the caps and the common questions.

Ask a question... ⌘I