Skip to main content
Sandboxes run untrusted or short-lived code in an isolated microVM and capture its output, useful for agent tool-calls, REPLs, and one-off jobs. The engine’s iii-sandbox router serves the sandbox::* functions and forwards each call to a sandbox adapter. The sandbox-libkrun worker is the adapter that runs the VMs, and Compose installs it from the registry when a project needs it: when the compose file sets engine.sandbox for its own namespace, when it declares a worker that runs in a VM (a bundle worker, or a path:// worker with runtime.base_image), or when you run iii call compose::add worker=iii-sandbox. To change which images the adapter allows, set its configuration under containers.sandbox-libkrun.config_override:
worker-compose.yaml
image_allowlist and custom_images set the images a sandbox can boot. An engine that no Compose file manages has no adapter bound, so its sandbox::* calls fail with S303 until you set a top-level sandbox: section in its engine config. Upgrading to the sandbox worker covers that case and the move from the 0.25 setup.
This page is a quick tour of the sandbox functions. For the adapter’s own documentation, see the sandbox-libkrun docs.
Sandboxes work through the worker’s sandbox::* functions, called the same way as any other function (see Call a function). Images are catalog names such as python or node, not arbitrary OCI references. You drive sandboxes by calling the worker’s sandbox::* functions, the same way you call any function (see Call a function). Images are catalog names such as python or node, not arbitrary OCI references. The examples below capture the new sandbox’s id with jq and stop the sandbox when done so nothing keeps running.

One-shot run

sandbox::run boots a VM, runs a snippet, captures its output, and stops the VM in a single call, so there is nothing to clean up.
lang accepts node, python, shell, or an interpreter path. Pass keep_sandbox=true to leave the VM running afterwards, and stop it yourself with sandbox::stop.

Lifecycle

For multi-step work, create a sandbox, operate on it with its id, then stop it. Every function takes a sandbox_id plus its own fields. A cmd that contains whitespace, with args and argv empty, is split into the binary and its arguments.
Most functions take flat key=value arguments; only nested payloads need --json. The adapter caps the stdout and stderr that sandbox::exec and sandbox::run return. When it cuts one, the reply sets stdout_truncated or stderr_truncated to true. For large output, write it to a file in the sandbox and fetch it with sandbox::fs::read.
The split of cmd is not a shell. It does not expand variables or chain commands. Use sandbox::run with lang: "shell" for shell semantics.
A contract 1.0 adapter sends neither truncation key, and the router passes its reply through unchanged, so a missing key means unknown, not false. Trust a false only from an adapter whose contract minor is 1 or later. The adapter’s contract version is info.contract in the sandbox::adapter::info reply; the top-level contract there is the router’s own.

Concurrency and idle cleanup

A sandbox accepts up to max_concurrent_exec_per_sandbox simultaneous sandbox::exec calls (four by default). Concurrent execs share the guest filesystem and process table without mutual exclusion, so coordinate commands that mutate shared state. sandbox::list reports exec_in_flight and exec_slots_free. Idle cleanup treats an active exec or relayed TCP, UDP, or DNS payload as activity, so a sandbox serving network traffic is not automatically stopped while it is handling requests. Bare acknowledgements and keepalive probes do not count as activity. Each exec remains bounded by max_exec_timeout_ms, and you should still call sandbox::stop when the sandbox is no longer needed.
exec_in_progress only reports whether at least one exec is running. It does not mean the next call will be rejected.

Catalog

sandbox::catalog::list reports the images this engine can boot: the bundled presets plus any image the operator registered. Call it when you do not already know what is available.

Filesystem

The sandbox::fs::* functions manipulate files inside a running sandbox. Each takes a sandbox_id plus operation-specific fields.
sandbox::fs::write takes a UTF-8 body in content, a base64 body in content_b64, or a stream channel. sandbox::fs::read returns body inline for a text file under the adapter’s 1 MiB cap, and always returns a content channel for the full bytes, so a large or binary file stays off the call payload.

Error codes

A failed sandbox::* call returns one error shape: a stable code (S-code), a type, a message, a retryable flag, and a docs_url that links to the matching entry below. A failed sandbox::* call returns the same error shape whichever sandbox adapter serves it: a stable code (S-code), a type, and a retryable flag. The codes belong to the engine’s sandbox contract, not to any one worker: they are part of the public sandbox::* API that every caller sees, the router returns S301-S303, and every adapter returns the rest. The docs_url in the error payload links to the matching entry below.
  • S001 (validation): request payload failed validation (e.g. missing/malformed sandbox_id)
  • S002 (validation): sandbox uuid not found in registry
  • S003 (validation): sandbox is at its exec concurrency cap (max_concurrent_exec_per_sandbox, default 4); a slot frees when any in-flight exec finishes, but detach foreground processes rather than waiting on them
  • S004 (validation): sandbox already stopped; create a new one
  • S100 (config): image not in catalog or allowlist
  • S101 (internal): rootfs missing on disk; enable auto_install or pre-provision cache
  • S102 (transient): auto-install pull/extract failed; retry
  • S200 (execution): exec exceeded timeout_ms
  • S210 (filesystem): fs op rejected by supervisor as invalid
  • S211 (filesystem): path does not exist
  • S212 (filesystem): path is wrong type (file vs dir)
  • S213 (filesystem): path already exists
  • S214 (filesystem): directory is not empty
  • S215 (filesystem): permission denied
  • S216 (filesystem): generic fs I/O failure
  • S217 (filesystem): invalid regex/pattern in grep or sed
  • S218 (transient): fs streaming channel aborted mid-flight; retry
  • S219 (filesystem): fs op unsupported by this supervisor; upgrade the sandbox adapter
  • S300 (platform): VM boot or supervisor session failure
  • S301 (transient): AdapterUnavailable: the sandbox adapter is not connected; retry once it is up
  • S302 (config): ContractMismatch: the adapter implements a different contract major version than the engine
  • S303 (config): NoAdapterConfigured: this engine has no sandbox adapter; set sandbox.adapter in its engine config
  • S304 (platform): OperationUnsupported: the adapter does not implement this operation
  • S400 (config): resource limit exceeded (cpu/memory/concurrency cap)
  • S501 (validation): SourceRejected: bad manifest, or host_path outside the allowed roots
  • S502 (validation): StateBusy: a VM already holds this state key; fix carries the live vm_id and instance
  • S503 (validation): InstanceMismatch: the request names a different instance than the live VM; fix carries the live vm_id and instance
  • S504 (validation): VmNotFound: no VM with this vm_id
  • S505 (validation): Unauthorized: the request auth token does not match
  • S506 (transient): PrepareFailed: worker::prepare failed; retry
The codes belong to the sandbox contract, not to one worker.