Skip to main content
Run commands inside a running sandbox: collect output in one shot, stream it as it arrives, attach an interactive PTY, or pipe data to stdin. These methods live on a running Sandbox. See Commands for usage examples.

Typical flow

Run and collect

sandbox.exec()

Run a command inside the sandbox and wait for it to complete. Collects all stdout and stderr into memory and returns them along with the exit code. For long-running processes or large output, use execStream() instead.

Parameters

cmdstring
Command to execute (e.g. “python3”, “/usr/bin/node”).
args?Iterable<string>
Command arguments (e.g. [“-c”, “print(‘hello’)”]).

Returns

Collected stdout, stderr, and exit status.

sandbox.execWith()

Run a command with per-execution overrides. Configure working directory, environment variables, timeout, stdin, TTY allocation, and rlimits via the builder callback. These overrides apply only to this execution and don’t change the sandbox’s defaults.

Parameters

cmdstring
Command to execute.
Builder callback for per-call overrides.

Returns

Collected stdout, stderr, and exit status.

sandbox.shell()

Run a command through the sandbox’s configured shell (defaults to /bin/sh). Shell syntax like pipes, redirects, and && chains works.

Parameters

scriptstring
Shell command string (e.g. “ls -la /app && echo done”).

Returns

Collected stdout, stderr, and exit status.

sandbox.attachShell()

Bridge your terminal to the sandbox’s default shell in a fully interactive PTY session.

Returns

Promise<number>
Exit code of the shell process.

Stream and attach

sandbox.execStream()

Run a command with streaming output. Returns a handle that emits stdout, stderr, and exit events as they happen, rather than buffering everything.

Parameters

cmdstring
Command to execute.
args?Iterable<string>
Command arguments.

Returns

Streaming handle for receiving events and controlling the process.

sandbox.execStreamWith()

Streaming variant of execWith(): same configuration via ExecOptionsBuilder, but returns an ExecHandle instead of buffering output. For sessions configured with .tty(true), call resize(rows, cols) when the terminal dimensions change.

Parameters

cmdstring
Command to execute.
Builder callback for per-call overrides.

Returns

Streaming handle.

sandbox.shellStream()

Run a shell command with streaming output.

Parameters

scriptstring
Shell command string.

Returns

Streaming handle.

sandbox.attach()

Bridge your terminal directly to a process inside the sandbox for a fully interactive PTY session. Press Ctrl+] (or configured detach keys) to disconnect without stopping the process.

Parameters

cmdstring
Command to run.
args?Iterable<string>
Command arguments.

Returns

Promise<number>
Exit code of the process.

sandbox.attachWith()

Interactive PTY attach with options for arguments, environment variables, working directory, user, custom detach keys, and rlimits. Configure via the builder callback.

Parameters

cmdstring
Command to run.
Builder callback for the attach session.

Returns

Promise<number>
Exit code of the process.

Types

ExecOutput

Returned by exec() · execWith() · shell() · ExecHandle.collect()

The result of a completed command execution: collected output plus exit status. In TTY mode, stdoutBytes() contains the combined terminal output and stderrBytes() is empty because a PTY doesn’t preserve separate stdout and stderr streams.

ExecHandle

Returned by execStream() · execStreamWith() · shellStream()

A handle to a running streaming execution. Implements AsyncIterable<ExecEvent> and AsyncDisposable, so it works with for await...of and await using. signal(), kill(), and resize() may run while another task is waiting in recv(); concurrent receive, wait, and collect operations are not supported.

ExecSink

Returned by ExecHandle.takeStdin()

Writer for sending data to a running process’s stdin. Implements AsyncDisposable. Obtained from ExecHandle.takeStdin() when the execution was configured with .stdinPipe().

ExecEvent

Emitted by ExecHandle

Discriminated union emitted while iterating an ExecHandle. The discriminator is kind.

ExitStatus

Returned by ExecHandle.wait() · ExecOutput.status

The exit result of a process.

ExecOptionsBuilder

Used by execWith() · execStreamWith()

Fluent builder passed to the callback in execWith(cmd, b => ...) and execStreamWith(cmd, b => ...). Every setter mutates the builder and returns it, so calls chain.

AttachOptionsBuilder

Used by attachWith()

Fluent builder passed to the callback in attachWith(cmd, b => ...). Every setter mutates the builder and returns it, so calls chain.

Stdin

Produces StdinMode

Helper factory for constructing a StdinMode. Equivalent to the stdinNull / stdinPipe / stdinBytes setters on ExecOptionsBuilder.

StdinMode

Produced by Stdin

Discriminated union describing stdin behavior for an execution.

Rlimit

Set via ExecOptionsBuilder.rlimit() · AttachOptionsBuilder.rlimit()

A POSIX resource limit applied to the process.

RlimitResource

Used by Rlimit.resource · rlimit() · rlimit()

String union naming a limitable POSIX resource.