Create a sandbox
Claims a pre-warmed microVM from the template's pool (or restores a snapshot), binds a fresh identity to it (new entropy, machine ID and clock) and returns it running. The sandbox stops when `timeout_s` passes unless you extend it, and `on_idle: pause` pauses it instead. It bills `sandboxes.vcpu_ms` (CPU used) and `sandboxes.gib_ms` (memory allocated) while running. `api` grants code inside the sandbox access to B3OS (`http://127.0.0.1:7700`) with scopes that must be a subset of yours; `sandboxes:write`, every `vault:*` and every `platform:*` scope are never granted unless named explicitly. `api.spend_cap_usd` may not exceed your own spend cap, and `null` means your cap applies; scopes or a cap beyond yours are refused with `403 forbidden`, `reason: scope_escalation`. Inside the sandbox the environment also has `B3OS_API_URL=http://127.0.0.1:7700`, `B3OS_SANDBOX_ID`, `B3OS_PROJECT` and `B3OS_PORT_BASE_PATH=/sbx/<host_id>`. `B3OS_PORT_BASE_PATH` is only the fixed start of every port preview path on `usercontent.b3os.org`, not a full base path: the full prefix of a request, `/sbx/<host_id>/<port>/<token>`, arrives with it in `X-Forwarded-Prefix` (`sandboxesProxyPortGet`). `timing` phases: `validate_ms`, then `claim_ms` and `resume_ms` for a pre-warmed microVM from the pool, or `restore_ms` when none was parked (a restore on demand, or from a snapshot), then `bind_ms` (the identity and environment reach the guest agent), and `total_ms`. A create that has started finishes even if the client disconnects before the response: the sandbox then runs (and is billed) until its timeout or a delete, and `GET /v1/sandboxes` lists it with the `metadata` it was created with. After a disconnect, look for it there before you retry: a retry is a new create, also with the same `Idempotency-Key`, because the key is released when the client goes away before the response. Fork, snapshot, pause and resume also finish after a disconnect.
/v1/sandboxes
Authentication
Header Parameters
Idempotency-Key
string
optional
header
Request Body
application/jsontemplate
string
snapshot
string
vcpu
integer
memory_mib
integer
disk_gib
integer
timeout_s
integer
on_idle
string
stop, pauseenv
object
secrets
object
ports
object[]
port
integer
REQUIRED
public
boolean
api
object
scopes
string[]
spend_cap_usd
number | null
connections
string[]
egress
object
mode
string
public, allowlist, denyallow
string[]
forkable
boolean
metadata
object
Responses
application/jsonid
string
REQUIRED
object
string
REQUIRED
sandboxstatus
string
REQUIRED
running, paused, stopped, failedhost_id
string
REQUIRED
template
object
REQUIRED
id
string
REQUIRED
name
string
REQUIRED
snapshot
string | null
REQUIRED
vcpu
integer
REQUIRED
memory_mib
integer
REQUIRED
disk_gib
integer
REQUIRED
timeout_s
integer
REQUIRED
on_idle
string
REQUIRED
stop, pauseexpires_at
string (date-time)
REQUIRED
env
object
REQUIRED
secret_names
string[]
REQUIRED
ports
object[]
REQUIRED
port
integer
REQUIRED
public
boolean
REQUIRED
url
string (uri) | null
REQUIRED
api
object
REQUIRED
scopes
string[]
REQUIRED
spend_cap_usd
number | null
REQUIRED
connections
string[]
REQUIRED
egress
object
REQUIRED
mode
string
REQUIRED
public, allowlist, denyallow
string[]
REQUIRED
forkable
boolean
REQUIRED
created_at
string (date-time)
REQUIRED
started_at
string (date-time)
REQUIRED
paused_at
string (date-time) | null
REQUIRED
stopped_at
string (date-time) | null
REQUIRED
stop_reason
string | null
REQUIRED
deleted, timeout, failed, nullusage
object
REQUIRED
vcpu_ms
integer
REQUIRED
gib_ms
integer
REQUIRED
timing
object
total_ms
number
REQUIRED
metadata
object
REQUIRED
curl -X POST 'https://beta-api.b3os.org/v1/sandboxes' \ -H 'Authorization: Bearer YOUR_API_TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "template": "base", "snapshot": "string", "vcpu": 1, "memory_mib": 512, "disk_gib": 1, "timeout_s": 300, "on_idle": "stop", "env": {}, "secrets": {}, "ports": [ { "port": 1, "public": false } ], "api": { "scopes": [ "vision:read" ], "spend_cap_usd": 0, "connections": [ "string" ] }, "egress": { "mode": "public", "allow": [ "string" ] }, "forkable": false, "metadata": { "customer": "acme", "ticket": "ENG-1423" }}'
const response = await fetch('https://beta-api.b3os.org/v1/sandboxes', { method: 'POST', headers: { "Authorization": "Bearer YOUR_API_TOKEN", "Content-Type": "application/json" }, body: JSON.stringify({ "template": "base", "snapshot": "string", "vcpu": 1, "memory_mib": 512, "disk_gib": 1, "timeout_s": 300, "on_idle": "stop", "env": {}, "secrets": {}, "ports": [ { "port": 1, "public": false } ], "api": { "scopes": [ "vision:read" ], "spend_cap_usd": 0, "connections": [ "string" ] }, "egress": { "mode": "public", "allow": [ "string" ] }, "forkable": false, "metadata": { "customer": "acme", "ticket": "ENG-1423" } })});const data = await response.json();console.log(data);
import requestsheaders = { 'Authorization': 'Bearer YOUR_API_TOKEN'}response = requests.post('https://beta-api.b3os.org/v1/sandboxes', headers=headers, json={ "template": "base", "snapshot": "string", "vcpu": 1, "memory_mib": 512, "disk_gib": 1, "timeout_s": 300, "on_idle": "stop", "env": {}, "secrets": {}, "ports": [ { "port": 1, "public": false } ], "api": { "scopes": [ "vision:read" ], "spend_cap_usd": 0, "connections": [ "string" ] }, "egress": { "mode": "public", "allow": [ "string" ] }, "forkable": false, "metadata": { "customer": "acme", "ticket": "ENG-1423" }})print(response.json())
{ "id": "sbx_01m5t68q1b590rj801nbzsqzkk", "object": "sandbox", "status": "running", "host_id": "sbx-01m5t68q1b590rj801nbzsqzkk", "template": { "id": "tpl_01m5t59b2ps0djyzdf082s18bz", "name": "base" }, "snapshot": null, "vcpu": 2, "memory_mib": 2048, "disk_gib": 4, "timeout_s": 900, "on_idle": "stop", "expires_at": "2026-10-25T19:15:00.004Z", "env": { "PROJECT": "demo" }, "secret_names": [], "ports": [ { "port": 3000, "public": false, "url": null }, { "port": 8080, "public": true, "url": "https://usercontent.b3os.org/sbx/sbx-01m5t68q1b590rj801nbzsqzkk/8080/pt1.n1.1793559600.zijFIOH2DvE3o_MHqQdESQat3b8k_izPyTDLu7qovZd3luYLULkaGmr6X02r7wRO5MmBNCZVzTV8qWsR4wDnBQ/" } ], "api": { "scopes": [ "vision:run", "infer:run" ], "spend_cap_usd": null, "connections": [] }, "egress": { "mode": "public", "allow": [] }, "forkable": false, "created_at": "2026-10-25T19:00:00.000Z", "started_at": "2026-10-25T19:00:00.004Z", "paused_at": null, "stopped_at": null, "stop_reason": null, "usage": { "vcpu_ms": 0, "gib_ms": 0 }, "timing": { "validate_ms": 0.2, "claim_ms": 0.01, "resume_ms": 0.3, "bind_ms": 1.2, "total_ms": 1.8 }, "metadata": {}}
Try this endpoint
/v1/sandboxes