Create a sandbox (E2B)
E2B's `POST /v2/sandboxes`. Claims a warm microVM of the template (`base`, `code-interpreter`, `agent` or `browser`; E2B's default `base`), with `envVars`, `metadata` and `timeout` (seconds, default 300, at most the plan's limit). `autoPause: true` pauses the sandbox at its timeout instead of stopping it. Egress: `allow_internet_access: false` or `network.denyOut: ["0.0.0.0/0"]` alone denies all; that `denyOut` with `network.allowOut` hosts allows only those hosts (ports 80 and 443 unless named). The key needs `sandboxes:run` as well as `sandboxes:write` (`403` without it), since the answer's `envdAccessToken` grants `sandboxes:run` on the new sandbox. `Idempotency-Key` (the SDKs send one): a repeat with the same key and body from the same key returns the same sandbox with a new envd access token (the earlier one stays valid 60 seconds), for 24 hours; the token itself is never stored. Bills `sandboxes.vcpu_ms` and `sandboxes.gib_ms` while the sandbox runs.
/compat/e2b/v2/sandboxes
Authentication
Header Parameters
Idempotency-Key
string
optional
header
Request Body required
application/jsontemplateID
string
timeout
integer
metadata
object
envVars
object
autoPause
boolean
autoPauseMemory
boolean
autoResume
object
allow_internet_access
boolean
network
object
mcp
object
volumeMounts
object[]
iam
object
Responses
application/jsonsandboxID
string
REQUIRED
templateID
string
REQUIRED
clientID
string
REQUIRED
envdVersion
string
REQUIRED
envdAccessToken
string
REQUIRED
domain
string | null
curl -X POST 'https://beta-api.b3os.org/compat/e2b/v2/sandboxes' \ -H 'Authorization: Bearer YOUR_API_TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "templateID": "base", "timeout": 300, "metadata": { "run": "demo" }, "envVars": { "GREETING": "hello" }}'
const response = await fetch('https://beta-api.b3os.org/compat/e2b/v2/sandboxes', { method: 'POST', headers: { "Authorization": "Bearer YOUR_API_TOKEN", "Content-Type": "application/json" }, body: JSON.stringify({ "templateID": "base", "timeout": 300, "metadata": { "run": "demo" }, "envVars": { "GREETING": "hello" } })});const data = await response.json();console.log(data);
import requestsheaders = { 'Authorization': 'Bearer YOUR_API_TOKEN'}response = requests.post('https://beta-api.b3os.org/compat/e2b/v2/sandboxes', headers=headers, json={ "templateID": "base", "timeout": 300, "metadata": { "run": "demo" }, "envVars": { "GREETING": "hello" }})print(response.json())
{ "sandboxID": "sbx-01m5t68q1b590rj801nbzsqzkk", "templateID": "base", "clientID": "b3os", "envdVersion": "0.5.7", "envdAccessToken": "b3os_et_BeHVb2oQkV3ZzHdpPJ2b0rlwxn6jQe7fT1sfJk0Uf2c", "domain": null}
Try this endpoint
/compat/e2b/v2/sandboxes