HTTP API
Call the sandbox API directly when no SDK fits. The SDKs and the fdtn command use the same API.
Basics
| Base URL | https://api.sbx.fdtn.dev |
|---|---|
| Auth | X-API-Key: fdtn_... on every request. API keys |
| Body | JSON, at most 1 MiB. An unknown field gets 400. |
| Times | Lifetimes in seconds. Times in answers are ISO 8601 UTC. |
| CPU type | 64-bit Arm (arm64). CPU type |
| Rate limit | Over the limit: 429 rate_limited. Wait Retry-After seconds. |
$ export FDTN_API_KEY=fdtn_... $ curl -s https://api.sbx.fdtn.dev/v2/sandboxes -H "X-API-Key: $FDTN_API_KEY"
Create a sandbox
POST /v2/sandboxes. All fields are optional.
| Field | Default | What it does |
|---|---|---|
templateID | "base" | Template name or ID. The template sets the size. |
timeout | 300 | Lifetime in seconds, 1 to 86400. |
metadata | {} | Your labels, plus the create options. Up to 64 string pairs; keys 1 to 128 bytes, values up to 1024. |
envVars | {} | Environment variables for every command. After a resume, send them with each command. |
autoPause | false | true pauses in place of a kill when the lifetime ends. |
allow_internet_access | true | false blocks all outbound traffic. |
network.allowPublicTraffic | false | true opens ports without a token. |
network.allowOut, denyOut | none | Outbound addresses or ranges to allow or block. |
$ curl -s -X POST https://api.sbx.fdtn.dev/v2/sandboxes \
-H "X-API-Key: $FDTN_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: eval-1-task-7" \
-d '{"templateID": "base", "timeout": 300, "metadata": {"run": "eval-1"}}'Answer 201 Created (shortened):
{
"sandboxID": "i7f3k2m9q0w8e4r6t1y5u",
"templateID": "stzjqps25y2abej5a5mn",
"alias": "base",
"envdAccessToken": "...",
"trafficAccessToken": "..."
}envdAccessToken opens the sandbox for commands and files. trafficAccessToken opens private ports. Keep both secret.
Queue and retries
- When machines are busy, the create waits in the queue for up to 30 minutes. Set your HTTP timeout to at least 1,800 seconds.
- Without
Idempotency-Key, a closed connection stops the create, and no sandbox stays. - With
Idempotency-Key(1 to 128 visible ASCII characters), the create continues after a closed connection. Send the same key and body again to get the same answer. A key lasts 24 hours. - The same key with a different body gets
409 idempotency_key_conflict.
Create options
These metadata keys change where and how a sandbox starts. Values are strings. A wrong value gets 400.
| Key | Values | Effect |
|---|---|---|
class | interactive (default), batch | Interactive creates go first in the queue. Use batch for jobs that can wait. |
vcpu | whole number | Optional check. It must equal the template's vCPU count, or 400. |
ram_gib | whole number | Optional check. It must equal the template's memory, or 400. Do not send it for a template with less than 1 GiB or part GiBs. |
disk_gib | whole number | Optional check. More than the template's disk gets 400 disk_over_included. |
fdtn_own_fleet_only | 1 | Start only on computers that Foundational Compute owns. The claude template always sets it. |
Do not use these option names as your own labels: class, vcpu, ram_gib, disk_gib, region, zip, region_mode. Other fdtn_ keys are reserved.
CPU type
Every sandbox runs on 64-bit Arm (arm64). Inside the sandbox, uname -m prints aarch64.
- Use arm64 builds of binaries and packages. Most Linux packages and language runtimes have them.
- A template image must have an arm64 build. Multi-arch images, such as the official Python, Node.js, Debian and Ubuntu images, work.
Sandbox endpoints
| Endpoint | What it does | Answer |
|---|---|---|
POST /v2/sandboxes | Create. | 201 |
GET /v2/sandboxes | List. Query state, metadata, limit. | 200 |
GET /sandboxes/{id} | Get one. | 200 |
DELETE /sandboxes/{id} | Kill. Files are deleted. | 204 |
POST /sandboxes/{id}/pause | Pause. Memory and files stay. | 204 |
POST /v2/sandboxes/{id}/connect | Get a sandbox and its tokens. A paused one resumes. Body timeout. | 200 running, 201 resumed |
POST /sandboxes/{id}/timeout | Set the time left from now. Body timeout, 0 to 86400. | 204 |
POST /sandboxes/{id}/refreshes | Make the time left at least duration seconds (0 to 3600). | 204 |
PUT /sandboxes/{id}/network | Replace outbound rules: allow_internet_access, allowOut, denyOut. | 204 |
GET /sandboxes/{id}/metrics | CPU, memory and disk (bytes), a sample about every 5 seconds. Query start, end (Unix seconds). | 200 |
GET /sandboxes/metrics | Newest sample for each of sandbox_ids (1 to 100, comma-separated). | 200 |
GET /sandboxes/{id}/logs | Log lines. Query start (Unix ms). | 200 |
POST /sandboxes/{id}/snapshots | Save as a template. Body name. Create from it, and delete it with DELETE /templates/{name}. | 201 |
Metrics and logs also work for a sandbox that ended recently. Other routes get 404. Paused limits
List sandboxes
state:running,pausedorrunning,paused.metadata: URL-encodedkey=value.- The answer is usually one page with all matches.
limitapplies to each computer, so you can get more rows thanlimit. - If the answer has an
X-Next-Tokenheader, send its value back asnextTokenfor the next page.
$ curl -s "https://api.sbx.fdtn.dev/v2/sandboxes?state=running,paused&metadata=run%3Deval-1" \
-H "X-API-Key: $FDTN_API_KEY"Examples
$ ID=i7f3k2m9q0w8e4r6t1y5u $ H="X-API-Key: $FDTN_API_KEY"; J="Content-Type: application/json" $ curl -s -X POST https://api.sbx.fdtn.dev/sandboxes/$ID/pause -H "$H" $ curl -s -X POST https://api.sbx.fdtn.dev/v2/sandboxes/$ID/connect -H "$H" -H "$J" -d '{"timeout": 600}' $ curl -s -X POST https://api.sbx.fdtn.dev/sandboxes/$ID/timeout -H "$H" -H "$J" -d '{"timeout": 1800}' $ curl -s -X PUT https://api.sbx.fdtn.dev/sandboxes/$ID/network -H "$H" -H "$J" -d '{"allow_internet_access": false}' $ curl -s -X POST https://api.sbx.fdtn.dev/sandboxes/$ID/snapshots -H "$H" -H "$J" -d '{"name": "worker-ready"}' $ curl -s -X DELETE https://api.sbx.fdtn.dev/sandboxes/$ID -H "$H"
Template endpoints
fdtn template create calls steps 1 to 4 in order. A build is free. At a spending limit, new builds stop.
| Endpoint | What it does | Answer |
|---|---|---|
GET /templates | Your templates and the public ones. | 200 |
GET /templates/{id} | One template and its builds. | 200 |
GET /templates/aliases/{name} | Does a name exist. | 200 or 404 |
DELETE /templates/{id or name} | Delete a template or snapshot. | 204 |
POST /v3/templates | 1. Request a build: name, tags, cpuCount (2), memoryMB (1024), minFreeDiskMb. | 202 + IDs |
GET /templates/{id}/files/{hash} | 2. Upload link for one file layer. | 201 |
POST /v2/templates/{id}/builds/{buildID} | 3. Start: fromImage or fromTemplate, fromImageRegistry, steps, startCmd, readyCmd, force. | 202 |
GET /templates/{id}/builds/{buildID}/status | 4. Status and new log lines. Query logsOffset, limit, level. | 200 |
GET /templates/{id}/builds/{buildID}/logs | Build log. | 200 |
GET /templates/{id}/tags | List tags. | 200 |
POST, DELETE /templates/tags | Add (target as name:tag, tags) or remove (name, tags). | 2xx |
GET /storage | Bytes your workspace stores (used_bytes) and the limit (limit_bytes, 0 = none). | 200 |
cpuCount1 to 16.memoryMBup to 32768, rounded up to 512 MiB blocks. Over:400.- Disk follows memory: up to 512 MiB gets 5 GiB, up to 2 GiB gets 10 GiB, more gets 20 GiB.
- A name has at most 128 bytes, with no
--or/. - The image must have an arm64 build. CPU type
- Private registry: send
fromImageRegistrywith typeregistry,usernameandpassword. - When no computer has room to build, the status is
waiting. The build starts by itself.
Secret endpoints
Save secrets that sandboxes use through the gateway. No answer ever holds the value. Secrets
| Endpoint | What it does | Answer |
|---|---|---|
POST /secrets | Save a key. Body name, value, metadata with the fdtn. rules. | 201 |
GET /secrets | List names, versions and rules. | 200 |
GET /secrets/{id} | Get one. | 200 |
PATCH /secrets/{id} | Rotate. Body value. Running sandboxes use the new version on their next call. | 200 |
DELETE /secrets/{id} | Delete. Running sandboxes lose access within about 15 seconds. | 204 |
To use a key, set an environment variable at create to fdtn-secret://<name>.
Save errors: 400 hosts_required or scope_required (add the fdtn.hosts, fdtn.paths and fdtn.methods keys), 400 value_too_large (over 64 KiB), 409 secret_exists (the name is taken), 403 secret_limit (100 keys per workspace).
Ports
https://<port>-<sandboxID>.sbx.fdtn.dev. Private ports need the traffic token in the e2b-traffic-access-token header. Ports and URLs
Errors
Errors are JSON with code (the HTTP status), message and sometimes error_code. When an answer has Retry-After, wait that many seconds and try again. Troubleshooting
{"code": 429, "error_code": "rate_limited", "message": "Rate limit exceeded. Slow down and retry after the Retry-After interval."}| Status | error_code | Meaning and fix |
|---|---|---|
400 | none | A wrong body, parameter or field. The message names it, or gives a ref to send to support. |
400 | disk_over_included | disk_gib or minFreeDiskMb is more than the size's disk. |
400 | invalid_idempotency_key | The key is empty, too long, or sent twice. |
400 | trusted_copy_not_supported | A fdtn_own_fleet_only sandbox cannot make a snapshot. |
401 | none | Key missing, wrong or expired. |
403 | none | Credit spent, a failed payment, or a spending limit. Open Billing. |
404 | none | No such sandbox, template or route. |
404 | template_not_available | No free computer has this template ready. The message lists templates that work. |
409 | none | The sandbox is changing state. Try again. |
409 | idempotency_key_conflict | This key was used with a different body. |
409 | create_result_unknown | The first create with this key has no saved answer. List sandboxes by metadata before you try again. |
413 | none | Body or file upload too large. |
429 | rate_limited | Too many requests. Wait Retry-After seconds. |
429 | sandbox_queue_full | 200 of your creates already wait. |
429 | paused_storage_limit | Paused sandboxes hold 100 GiB of memory. Kill or resume some. |
429 | storage_limit | Your workspace stores its limit of paused sandboxes, snapshots and templates. Delete some. |
429 | template_limit | 100 templates and snapshots. Delete some. |
429 | upload_budget | 10 GiB of template files uploaded today. Try after 00:00 UTC. |
429 | none | A resume or build that cannot start now. Wait Retry-After seconds. |
500, 502, 504 | sandbox_create_failed | The sandbox could not start. Try again. |
503 | sandbox_capacity_unavailable | No room now, or no room after 30 minutes in the queue. Try again later. |
503 | sandbox_architecture_unavailable | Build: the image has no arm64 build. Use a multi-arch or arm64 image. |
503 | image_platform_unavailable | Build: the registry did not confirm the image has an arm64 build. Check the image name and registry login. |
503 | template_not_ready | The build has not finished, or failed. |
503 | trusted_device_unavailable | A fdtn_own_fleet_only sandbox cannot resume on its computer. |
503 | sandbox_device_offline | The paused sandbox is saved, but its computer is offline. Try again later. |
503 | other codes | A short wait, for example sandbox_busy or sandbox_state_moving. Wait Retry-After seconds and try again. |