Skip to main content

Overview

Shell commands and Python code share the same filesystem:
An export inside a command doesn’t cross between shell and Python: sandbox.commands.run("export FOO=bar") is not visible in sandbox.code.run(...). Set env at creation for variables both sides should see, and use the filesystem to share data between the two afterwards.

Return values

sandbox.commands.run(cmd)

Returns a command result:

sandbox.code.run(code)

Returns an execution result:
For commands that run long enough to bound, watch, or feed input to — timeouts, interrupts, streaming output, and stdin — see Process I/O.

Sandbox.create() parameters

snapshot

The snapshot to boot from. Defaults to alpine. See Snapshots for the full catalog.

mounts

Mount host directories into the sandbox. Paths are read-only by default; append :rw for read-write access.

env

Environment variables the guest starts with. They reach commands, anything those commands spawn, and code.run.
Values are passed literally, so quotes, $, and backticks in a value are never interpreted by the shell. Names must be plain identifiers.
Values set this way are visible inside the sandbox. Anything running there can read them from the environment, so treat env as configuration rather than a place for API keys or tokens. Use secrets for those.

secrets

A credential the sandbox can use but never read. The guest is given a stand-in through its environment; the value itself goes only to the network gateway, which swaps it back in on the way out, and only for a host you named.
Agent frameworks read credentials from the environment already, so code in the sandbox needs no changes. What it reads back is the stand-in:
Set placeholder yourself when a client library checks the shape of a key:
The sandbox cannot read the credential, but it can spend it: any code running there can call the allowlisted host and the gateway will authenticate the request. This hides the credential, it does not restrain its use.
A request carrying a stand-in to a host that is not on its list fails rather than going out unswapped, so a mistake surfaces as an error instead of a puzzling 401 somewhere else. Substitution covers the request line and headers, which is where every API this was built for puts its key; a credential sent in a JSON body is not swapped. A client that pins certificates cannot be used this way, because the gateway terminates TLS.

trace

Records what the sandbox actually did, which programs ran, which files changed and where it connected. Off unless you ask for it, and chosen at creation:
See Tracing.

engine

Some private snapshots come with their own engine, which runs the tools installed in them faster. With the default "auto", the sandbox uses that engine when it is already compiled, and otherwise starts on the engine bundled with the SDK while the snapshot’s engine is prepared in the background for next time. See Private snapshots. Pass "default" to always use the bundled engine:
sandbox.tier says which engine it got: "image" for the snapshot’s own, "aot" or "base" for the bundled one.