Foundational Compute

HTTP API

Call the sandbox API directly when no SDK fits. The SDKs and the fdtn command use the same API.

Basics

Base URLhttps://api.sbx.fdtn.dev
AuthX-API-Key: fdtn_... on every request. API keys
BodyJSON, at most 1 MiB. An unknown field gets 400.
TimesLifetimes in seconds. Times in answers are ISO 8601 UTC.
CPU type64-bit Arm (arm64). CPU type
Rate limitOver 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.

FieldDefaultWhat it does
templateID"base"Template name or ID. The template sets the size.
timeout300Lifetime 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.
autoPausefalsetrue pauses in place of a kill when the lifetime ends.
allow_internet_accesstruefalse blocks all outbound traffic.
network.allowPublicTrafficfalsetrue opens ports without a token.
network.allowOut, denyOutnoneOutbound 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.

KeyValuesEffect
classinteractive (default), batchInteractive creates go first in the queue. Use batch for jobs that can wait.
vcpuwhole numberOptional check. It must equal the template's vCPU count, or 400.
ram_gibwhole numberOptional 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_gibwhole numberOptional check. More than the template's disk gets 400 disk_over_included.
fdtn_own_fleet_only1Start 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

EndpointWhat it doesAnswer
POST /v2/sandboxesCreate.201
GET /v2/sandboxesList. Query state, metadata, limit.200
GET /sandboxes/{id}Get one.200
DELETE /sandboxes/{id}Kill. Files are deleted.204
POST /sandboxes/{id}/pausePause. Memory and files stay.204
POST /v2/sandboxes/{id}/connectGet a sandbox and its tokens. A paused one resumes. Body timeout.200 running, 201 resumed
POST /sandboxes/{id}/timeoutSet the time left from now. Body timeout, 0 to 86400.204
POST /sandboxes/{id}/refreshesMake the time left at least duration seconds (0 to 3600).204
PUT /sandboxes/{id}/networkReplace outbound rules: allow_internet_access, allowOut, denyOut.204
GET /sandboxes/{id}/metricsCPU, memory and disk (bytes), a sample about every 5 seconds. Query start, end (Unix seconds).200
GET /sandboxes/metricsNewest sample for each of sandbox_ids (1 to 100, comma-separated).200
GET /sandboxes/{id}/logsLog lines. Query start (Unix ms).200
POST /sandboxes/{id}/snapshotsSave 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, paused or running,paused.
  • metadata: URL-encoded key=value.
  • The answer is usually one page with all matches. limit applies to each computer, so you can get more rows than limit.
  • If the answer has an X-Next-Token header, send its value back as nextToken for 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.

EndpointWhat it doesAnswer
GET /templatesYour 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/templates1. 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}/status4. Status and new log lines. Query logsOffset, limit, level.200
GET /templates/{id}/builds/{buildID}/logsBuild log.200
GET /templates/{id}/tagsList tags.200
POST, DELETE /templates/tagsAdd (target as name:tag, tags) or remove (name, tags).2xx
GET /storageBytes your workspace stores (used_bytes) and the limit (limit_bytes, 0 = none).200
  • cpuCount 1 to 16. memoryMB up 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 fromImageRegistry with type registry, username and password.
  • 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

EndpointWhat it doesAnswer
POST /secretsSave a key. Body name, value, metadata with the fdtn. rules.201
GET /secretsList 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."}
Statuserror_codeMeaning and fix
400noneA wrong body, parameter or field. The message names it, or gives a ref to send to support.
400disk_over_includeddisk_gib or minFreeDiskMb is more than the size's disk.
400invalid_idempotency_keyThe key is empty, too long, or sent twice.
400trusted_copy_not_supportedA fdtn_own_fleet_only sandbox cannot make a snapshot.
401noneKey missing, wrong or expired.
403noneCredit spent, a failed payment, or a spending limit. Open Billing.
404noneNo such sandbox, template or route.
404template_not_availableNo free computer has this template ready. The message lists templates that work.
409noneThe sandbox is changing state. Try again.
409idempotency_key_conflictThis key was used with a different body.
409create_result_unknownThe first create with this key has no saved answer. List sandboxes by metadata before you try again.
413noneBody or file upload too large.
429rate_limitedToo many requests. Wait Retry-After seconds.
429sandbox_queue_full200 of your creates already wait.
429paused_storage_limitPaused sandboxes hold 100 GiB of memory. Kill or resume some.
429storage_limitYour workspace stores its limit of paused sandboxes, snapshots and templates. Delete some.
429template_limit100 templates and snapshots. Delete some.
429upload_budget10 GiB of template files uploaded today. Try after 00:00 UTC.
429noneA resume or build that cannot start now. Wait Retry-After seconds.
500, 502, 504sandbox_create_failedThe sandbox could not start. Try again.
503sandbox_capacity_unavailableNo room now, or no room after 30 minutes in the queue. Try again later.
503sandbox_architecture_unavailableBuild: the image has no arm64 build. Use a multi-arch or arm64 image.
503image_platform_unavailableBuild: the registry did not confirm the image has an arm64 build. Check the image name and registry login.
503template_not_readyThe build has not finished, or failed.
503trusted_device_unavailableA fdtn_own_fleet_only sandbox cannot resume on its computer.
503sandbox_device_offlineThe paused sandbox is saved, but its computer is offline. Try again later.
503other codesA short wait, for example sandbox_busy or sandbox_state_moving. Wait Retry-After seconds and try again.

Next