Engine & HTTP API
9 min read
teploy-sandbox (v0.1.0, early access, FSL-1.1-MIT) is a single-box
sandbox daemon written in Go. You can let teploy sandbox host manage it, or
run it directly and drive its /v1 HTTP API from your own tools, SDKs, or
agents.
Source and release binaries (statically linked Linux amd64 and arm64, built
with Go 1.26.11, plus checksums.txt):
github.com/useteploy/teploy-sandbox.
Running the engine directly
teploy-sandbox serveBy default, serve listens on 127.0.0.1:7439 and mints a bearer token to
/deployments/sandbox/token on first start (teploy sandbox host configures it
under /var/lib/teploy-sandbox/).
Verify a release download against checksums.txt before running:
sha256sum -c --ignore-missing checksums.txtCommon flags and environment variables
| Flag (env) | Default | Purpose |
|---|---|---|
--addr |
127.0.0.1:7439 |
Plain HTTP listen address (loopback or private network only — never public). |
--token-file |
/deployments/sandbox/token |
Bearer token file (minted if absent). |
--driver (SBX_DRIVER) |
docker |
docker (default) or vm (experimental). |
--state-dir (SBX_STATE_DIR) |
/var/lib/teploy-sandbox/state |
Persists stopped runs across restarts (0600 JSON inside 0700 dir). Set empty for memory-only. |
--stopped-retention (SBX_STOPPED_RETENTION) |
336h |
How long stopped runs and their snapshots are kept before reaping (14 days). |
--usage-interval (SBX_USAGE_INTERVAL) |
0 (off) |
Sampling interval for CPU, network, and disk usage observations. |
--sandbox-user (SBX_SANDBOX_USER) |
ship |
Non-root account inside Docker images when present (empty runs everything as root). |
--egress-allow (SBX_EGRESS_ALLOW) |
— | Deployment-wide additions to the allowlist proxy (host, .suffix, or host:port). |
--cache-root / --cache-max-gb |
/var/lib/teploy-sandbox/cache / 20 |
Warm repo cache directory and LRU size cap (empty --cache-root disables warm). |
--exec-recoverable-max-timeout (SBX_EXEC_RECOVERABLE_MAX_TIMEOUT) |
1h |
Upper bound on timeoutSec for recoverable execs (up to 24h). |
SBX_RUNTIME=runsc |
Docker default | Opt into gVisor for Docker containers (dev.gvisor.flag.overlay2=none is set per container so docker commit captures workspace changes). |
Wire contract & stability
The canonical specification is docs/wire-contract.md in the
teploy-sandbox repository.
- Authentication: every route except
GET /healthrequiresAuthorization: Bearer <token>. Missing or invalid tokens return401. - Stability: additive-only within
/v1. Clients must ignore unknown JSON fields, unknown status states, and unknown SSE event names. - Absent is not zero: optional fields (such as sampled
usagemetrics) are omitted when unknown, never filled with0orfalse. - Conventions: IDs are 26-character ULIDs; every JSON object response
carries
server(the daemon's hostname); durations are integer seconds (...Sec), timestamps are RFC 3339, sizes are bytes (...Bytes), memory is MiB (memoryMb).
Errors (application/problem+json)
{"type": "https://neutron.dev/errors/<kind>", "title": "...", "status": 409, "detail": "human-readable reason"}Parse the HTTP status and type suffix — detail is for humans only.
| Status | type suffix |
Meaning | Safe to retry? |
|---|---|---|---|
400 |
bad-request |
Invalid input or unsupported driver field. | No |
401 |
unauthorized |
Missing or wrong bearer token. | No |
404 |
not-found |
Missing run, exec, snapshot, file, or template. | No |
409 |
conflict |
Wrong state (busy, stopped, running, lease held/superseded, held by another daemon). |
Yes, after condition clears |
503 |
at-capacity |
VM cap or recoverable-exec slots full, or remote storage unreachable. | Yes, with backoff |
500 |
internal |
Unexpected server error. | Reads yes; check GET before retrying mutations |
Retry rules
GETroutes are safe to retry.DELETE /v1/runs/{id}: treat404after a lost answer as done.POST /v1/runsandPOST /v1/runs/{id}/forkare not idempotent: after a lost answer, list runs and match on yourlabelsbefore creating another.POST .../stopand.../resume: a retry after success returns409; read the run to confirm.POST .../execwithoutrecoverable: trueis not retryable once streaming begins. Withrecoverable: true, fetch status and output byX-Exec-Idinstead of re-sending.
Core HTTP routes
Health & capacity
| Route | Success | Response |
|---|---|---|
GET /health (no auth) |
200 |
{status: "ok", version} |
GET /v1/capacity |
200 |
{server, driver, runtime, nestedVirt, cpus, memoryMb, runs, allocated, warmPool?, access?, disk?} |
Runs
| Route | Request body | Success |
|---|---|---|
POST /v1/runs |
{image, env?, ttlSec?, network?, egressAllow?, limits?: {memoryMb?, cpus?, pids?}, warm?: {repo, path?}, user?, labels?, onExpire?} |
201, run object |
GET /v1/runs |
— | 200, {runs: [...]} |
DELETE /v1/runs/{id} |
— | 204 |
POST /v1/runs/{id}/stop |
— | 200, run object (state: "stopped") |
POST /v1/runs/{id}/resume |
{ttlSec?, takeover?, accessEpoch?} |
200, run object (state: "running") |
POST /v1/runs/{id}/fork |
{ttlSec?, labels?, onExpire?} |
201, new run object (with forkedFrom) |
Defaults on POST /v1/runs: ttlSec: 1800 (max 86400), network: "none",
limits: {cpus: 1, memoryMb: 1024, pids: 256}, onExpire: "destroy". Up to 16
labels per run (^[a-z0-9]([a-z0-9._-]{0,62})$, values up to 256 bytes, no
control characters). egressAllow is only valid with network: "allowlist"
(400 on none or open).
Example:
T=$(cat /var/lib/teploy-sandbox/token)
ID=$(curl -s -H "Authorization: Bearer $T" \
-d '{"image":"alpine:3.20","ttlSec":1800}' \
http://127.0.0.1:7439/v1/runs | jq -r .id)
curl -N -H "Authorization: Bearer $T" \
-d '{"cmd":"uname -a"}' \
"http://127.0.0.1:7439/v1/runs/$ID/exec"Exec & recoverable execs
POST /v1/runs/{id}/exec accepts
{cmd, cwd?, timeoutSec?, env?, owner?, generation?, outputEncoding?, recoverable?}
and responds with text/event-stream:
event: stdout
data: <chunk>
event: stderr
data: <chunk>
event: exit
data: {"exitCode":0,"timedOut":false}cmdruns undersh -cin/work(orcwd, confined to/work).timeoutSecdefaults to120.envallows up to 64 variables / 64 KiB, POSIX names, no NUL or line breaks.outputEncoding: "base64"sends byte-exact base64 chunks (preserving binary bytes and carriage returns); omitted defaults to UTF-8 text where invalid bytes become U+FFFD.- Without
recoverable: true, closing the SSE stream ends the command.
With "recoverable": true:
- Response headers include
X-Exec-Id: <ulid>immediately, and the command keeps running if the connection drops. - To resume output cleanly by byte offset, set
outputEncoding: "base64"— the count of decoded bytes received is the exactsinceoffset. - Bounds (not configurable in
v0.1.0): last 1 MiB of output per exec, 8 records per run, 64 per daemon, finished records kept 15 minutes. Records are memory-only and lost on daemon restart (404).
| Route | Purpose |
|---|---|
GET /v1/runs/{id}/execs |
List recoverable exec statuses for a run, oldest first. |
GET /v1/runs/{id}/execs/{execId} |
Read one exec's status (running, exited, timedOut, cancelled, failed). |
GET /v1/runs/{id}/execs/{execId}/output?since=&limit= |
Read base64 output chunks (limit default 65536, up to 4096 chunks per read; omit since for tail). |
DELETE /v1/runs/{id}/execs/{execId} |
Cancel a running exec (202, idempotent). Kills process group on VM driver; on Docker, releases the record and kills docker exec while the in-container process runs until timeout or run stop. |
Files, leases, snapshots, and warm repo cache
| Area | Routes | Notes |
|---|---|---|
| Files | PUT/GET /v1/runs/{id}/files/{path} |
Raw bytes up to 64 MiB, confined to /work. PUT takes lease ?owner=&generation=; GET is always open while running. |
| Leases | POST /v1/runs/{id}/lease, .../lease/renew, .../lease/release |
Exclusive writable fencing via {owner, generation} on execs and file writes; reads stay open. |
| Snapshots | POST /v1/runs/{id}/snapshot, DELETE /v1/snapshots?image=<ref> |
Commit a caller-owned teploy-sbx-snap:<ulid> image that survives TTL reaping. |
| Warm repo cache | POST /v1/runs/{id}/warm-commit, GET /v1/runs/{id}/warm, GET/DELETE /v1/warmcache/{owner}/{name} |
Per-repo copy-on-boot volumes keyed by repo slug, invalidated when the lockfile hash changes (Docker driver only). |
Surviving a daemon restart
- Stopped runs are stored atomically in
--state-dirand can be resumed after a restart. - Running containers never outlive their daemon: the startup sweep removes any leftover containers.
- On graceful shutdown, runs with
onExpire: "stop"are stopped and saved to the state file; all other running runs are destroyed. On a crash, no running run is stopped. - If a named
--state-diris unusable or a state file cannot be parsed, the daemon refuses to start rather than orphaning snapshots.
Experimental engine features
The following features exist in teploy-sandbox v0.1.0 and are experimental
and off by default:
- VM driver (
--driver vm): runs each sandbox as a Cloud Hypervisor microVM on KVM with a ZFS volume cloned from a golden snapshot andteploy-guestdover vsock. Not installed byteploy sandbox host. Requires root on Linux 5.13+ (x86-64 or arm64),/dev/kvm, cgroup v2, seccomp, Landlock, ZFS pool withvolmode=dev, uncompressed guest kernel, 4096 reserved UIDs, andiproute2/nftables/conntrack-tools. Refuseswarm,limits.pids, and images other thangoldenor VM snapshots (400). Seescripts/install-host.shandscripts/build-golden.shin the repository. - Warm VM pool (
--vm-warm): pre-boots idle VMs of declared sizes (CPUSxMEMORY=COUNT, VM driver only, off by default). - Memory stop and resume (
--vm-memory-snapshots): off by default, VM driver only. Saves guest RAM into a per-image encrypted ZFS dataset alongside the disk snapshot so same-host resumes keep live processes and open files. Disk stays the durable truth — whenever an image cannot be restored, resume falls back to booting the disk (resumedFrom: "disk"vs"memory"). Not supported on arm64 (lacksacpi=on/ VM Generation ID), andforkalways boots from disk. - Off-host S3 storage (
--remote-endpoint): VM driver only, off by default. Uploads encrypted incremental ZFS send streams so stopped runs can resume on another daemon (POST /v1/remote/{sync,collect,rotate,scrub},GET /v1/remote/snapshots). The repository README marks this not for real data yet — keep the default--remote-local keep(dropis refused). - Access listener (
--access-addr): off by default. Exposes a separate mTLS 1.3 (or Unix socket) listener for an external edge proxy (not part of this release) to forward signed Ed25519 grants (tsg1.*) to published guest ports (PUT/DELETE /v1/runs/{id}/ports/{port},POST /v1/runs/{id}/access/revoke,GET/PUT /v1/access/config).connectworks on the VM driver only (Docker returns501); SSHsessionis not built yet.