Sandbox CLI reference

9 min read

teploy sandbox drives a self-hosted teploy-sandbox daemon (v0.1.0, early access) on a server managed by Teploy. host takes <server> positionally; every other subcommand takes --host (a server name from servers.yml or a hostname/IP). All subcommands — including host — honor the standard --user and --key SSH flags.

Commands

Command Summary
teploy sandbox host <server> Install, start, or upgrade the pinned teploy-sandbox v0.1.0 service on <server>.
teploy sandbox new --image IMAGE Create a sandbox and print Created <id> on <server> (<image>, expires <time>) with a suggested exec line.
teploy sandbox ls List every sandbox on the server (running and stopped), oldest first.
teploy sandbox exec <id> -- <command> Run a command in a running sandbox and stream its output.
teploy sandbox cp <src> <dst> Copy one file (up to 64 MiB) into or out of a sandbox's /work.
teploy sandbox stop <id> Commit the filesystem, remove the container, and keep the sandbox as stopped.
teploy sandbox resume <id> Boot a stopped sandbox again under the same ID with a new deadline.
teploy sandbox fork <id> Start a new sandbox from a running or stopped sandbox's filesystem and settings.
teploy sandbox rm <id> Destroy a sandbox (and its stop snapshot if stopped). Asks first unless --yes.

stop on an already-stopped sandbox and resume on an already-running sandbox are not errors: the CLI reports the current state.

teploy sandbox host

teploy sandbox host <server> [--yes] [--json]

Downloads the pinned teploy-sandbox v0.1.0 release binary from github.com/useteploy/teploy-sandbox, verifies it against both the CLI's pinned SHA-256 (sandboxEngineSHA256) and the release's checksums.txt, checks that the binary reports the expected version on the server, and manages the teploy-sandbox systemd service. Platforms without a pinned hash are refused. Nothing is built on the server.

Files placed on the server:

What Path
Engine binary /usr/local/bin/teploy-sandbox
Previous binary (after an upgrade) /usr/local/bin/teploy-sandbox.prev (restored automatically if the new binary does not answer)
Systemd unit /etc/systemd/system/teploy-sandbox.service (root-owned, marked as written by teploy sandbox host)
Token (0600), stopped-run registry, warm cache /var/lib/teploy-sandbox/

A fresh install prompts for confirmation before installing the service unless --yes is passed.

Behavior on repeat runs:

  • Same version and unit file running: no changes.
  • Older release installed: prompts before upgrading (since restarting the engine affects running sandboxes), saves the old binary as .prev, and rolls back if the new engine fails to answer.
  • Unit file modified or from another CLI version: rewrites the unit (prompts if running, starts if stopped) and restores the old unit if the engine does not answer.
  • Service installed and stopped: starts it.
  • Binary missing while service exists: prompts before reinstalling the binary (and restarting if active, or starting if stopped).
  • Server has a newer release than the CLI: leaves it untouched; run teploy update first.

Restart impact. Restarting the engine follows the daemon's shutdown rule: running sandboxes created with --on-expire stop are stopped and preserved, all other running sandboxes are destroyed, already-stopped sandboxes stay, and any in-flight exec is cut off. The confirmation prompt prints the counts.

Refusals. host never overwrites an installation it did not create. A teploy-sandbox.service without its marker, a manually installed binary, another daemon already answering on 127.0.0.1:7439, or systemd drop-ins under teploy-sandbox.service.d/*.conf are refused with nothing changed.

host --json requires --yes (as does rm --json). When host changes something, it records a sandbox.host event in the server's history.

teploy sandbox new

teploy sandbox new --host <server> --image <IMAGE> [flags]
Flag Default Description
--image (required) Docker image to boot (or golden / snapshot image on a VM-driver server).
--ttl 30m Sandbox lifetime (up to 24h).
--network none Egress tier: none, allowlist, or open.
--env KEY=VALUE — Environment variable (repeatable).
--cpus 1 CPU limit.
--memory-mb 1024 Memory limit in MiB.
--pids 256 Process limit.
--run-as default The user commands run as inside the sandbox: default (ship if the image defines it, otherwise root) or root. (--user is the SSH user, as everywhere.)
--label KEY=VALUE — Metadata label (repeatable, at most 15 user labels; the CLI adds teploy.cli-run=<id>).
--on-expire destroy Behavior when the TTL passes: destroy or stop.
--driver docker Pass --driver vm to opt into a server already running the experimental VM driver.

teploy sandbox exec

teploy sandbox exec <id> --host <server> [--timeout 2m] [--env KEY=VALUE] [--workdir /work] -- <command>
  • -- ends Teploy's flags. A single word after -- is passed as a shell command line of its own, so shell syntax (|, >, &&) works inside one quoted word, e.g. -- 'ls -la /work | wc -l'. Multiple words are each quoted as your shell tokenized them so argument quoting survives, e.g. -- echo 'a b'.
  • --timeout defaults to 2m.
  • --workdir defaults to /work and must stay inside /work (/work/... may be written in full).

Exit status of exec

exec passes the remote command's exit status through, like ssh:

Exit code Meaning
0 Command exited 0.
124 Command ended by --timeout.
1–254 Command's own nonzero exit code (including 2).
255 Teploy or engine failure (unreachable engine, refusal, dropped stream before exit, bad invocation).

Because a command that exits 255 itself shares that exit code, --json distinguishes them via the error class (command-failed for the command).

teploy sandbox cp

teploy sandbox cp <local-file> <id>:<path> --host <server>
teploy sandbox cp <id>:<path> <local-file-or-dir> --host <server>

Copies one file up to 64 MiB. The sandbox side <id>:<path> is relative to /work (/work/... is also accepted). Copying out preserves the file mode of an existing destination file; new files are created 0644.

stop, resume, fork, rm

  • teploy sandbox stop <id> --host <server>
  • teploy sandbox resume <id> --host <server> [--ttl <duration>]
  • teploy sandbox fork <id> --host <server> [--ttl <duration>] [--label KEY=VALUE] [--driver <driver>]
  • teploy sandbox rm <id> --host <server> [--yes] (asks for confirmation unless --yes; --json requires --yes)

Connecting to another daemon

Pass --addr and --token-file on any command other than host to talk to a daemon installed manually or by teploy-ship:

  • --addr must be a loopback IP (127.0.0.1:7439, [::1]:7439) because the daemon speaks plain HTTP.
  • Reaching another IP or hostname requires --allow-remote-addr and should only be used on a trusted network.

Experimental VM driver

The CLI targets the Docker driver installed by host. The VM driver is experimental (requires KVM, a ZFS pool, and a golden guest image; every sandbox runs as root inside it and warm caches are unavailable).

  • teploy sandbox host --driver vm is refused.
  • Against a server already set up with the VM driver, pass --driver vm to new and fork; without it, the CLI refuses and names the flag.

Lost answers and retries

new and fork are sent once and never retried automatically, because a retry could create a duplicate sandbox. If the response is lost, the CLI reports an unknown outcome and tells you to run ls before trying again. Every sandbox created by the CLI carries the label teploy.cli-run=<id> so you can match it in ls.

If an exec stream drops before the exit frame arrives, closing the stream ends the command on the engine side, and the CLI reports an unknown outcome rather than re-sending it. Under --json, all of these report error code uncertain-outcome.

Machine output (--json)

Every --json response includes machine_interface at its root (capability sandbox-v1; schemas live in contracts/schema/sandbox-*.schema.json in teploy-cli) with snake_case fields:

Command JSON document
new, stop, resume, fork {machine_interface, server, host, run}
ls {machine_interface, server, host, driver, runs[]} (oldest first)
exec {machine_interface, server, host, run_id, exit_code, timed_out, duration_ms, stdout, stderr, truncated}
rm {machine_interface, server, host, run_id}
cp {machine_interface, server, host, run_id, path, direction, bytes}
host {machine_interface, server, host, ok, action, version, from, addr, token_file}

Details to rely on when scripting:

  • Measurements the engine did not take are omitted from usage, never reported as 0.
  • exec --json captures up to 1 MiB per stream (truncated flags overflow) instead of streaming live. Output is fetched byte-for-byte from release engines: if a stream contains invalid UTF-8, stdout_base64 or stderr_base64 is included alongside stdout/stderr (dev builds reporting version dev fall back to text mode where invalid bytes become U+FFFD).
  • exit_code is the command's exit code, -1 if the sandbox could not run it, or null if the stream died before the exit was known. If the engine refused the exec before accepting it (missing or stopped sandbox, bad ID), stdout is empty and only the error envelope is written to stderr.
  • host --json sets action to install, upgrade, repair (the pinned engine was present and its service file was rewritten), start, or unchanged. from is the version that was there, omitted on install and on an upgrade over a missing binary. Both host --json and rm --json require --yes.

Errors are written to stderr as an error envelope with one of these codes:

Code Meaning
unsupported Engine not installed, service stopped, VM driver unavailable, or CLI build lacks a pinned engine hash.
conflict Engine refused the request due to state (for example, exec on a stopped sandbox).
uncertain-outcome Response or stream was lost; outcome is not known.
command-failed Command exited nonzero or timed out.
internal Any other failure.

Not in this CLI release

  • Recoverable execs: the engine supports detached execs that survive stream drops, but teploy sandbox exec does not use that route yet.
  • Engine-only features: writable leases, caller-owned snapshots, warm repo caches, off-host remote storage, and published ports / SSH access exist on the engine API only — no CLI subcommand wraps them yet.
  • Systemd sandboxing on the unit: the teploy-sandbox service drives Docker and is root-equivalent; the boundary is loopback-only listening.