sandbox.commands.run().
This page covers
run(). If you need to send input to a process while it runs, like a REPL, spawn() keeps the session open instead.Using
AsyncSandbox? The same methods are there, awaitable. See the Sandbox reference.Handling exit codes
run() doesn’t throw on a non-zero exit code. Check exitCode on the result yourself.
Working directory and environment
Passcwd and env to control the execution context.
Watch the units: TypeScript takes
timeoutMs (milliseconds), Python takes timeout_seconds (seconds).USER, or the template’s user step). Pass user to run as someone else, like docker exec -u: a name or uid, optionally :group, e.g. user: "root" to install a package.
Timeouts
The timeout is a hard limit on how long a command runs. When it’s reached, the sandbox stops the command andrun() returns with exit code 124. It doesn’t throw, so check the exit code. Output doesn’t extend the limit: a command that keeps printing still stops on time.
Set a timeout on any
run() that can take longer than 30 seconds. For a process with no fixed end, like a server, use spawn() without one.
TypeScript rounds
timeoutMs up to whole seconds. run() treats timeoutMs: 0 the same as leaving it out, and throws ValidationError for a value that is negative, not finite, or out of range.Large output
Without callbacks,run() returns stdout and stderr in one JSON response, capped at 8 MiB of JSON-encoded output for both streams together. Characters that JSON escapes count for more than one byte (a < counts as six), so output with many of them is cut below 8 MiB of raw text. When the cap is reached, the sandbox drops the rest, sets truncated to true on the result, and appends a notice to stderr. The command itself still runs to the end.
truncated is always false.
For longer commands, stream the output as it runs. To send input to a process while it runs, open a session.