Sandbox. See Commands for usage examples.
Typical flow
Run and collect
sandbox.exec()
Example
Example
execStream() instead.
Parameters
cmdstring“python3”, “/usr/bin/node”).args?Iterable<string>[“-c”, “print(‘hello’)”]).Returns
sandbox.execWith()
Example
Example
Parameters
cmdstringReturns
sandbox.shell()
Example
Example
/bin/sh). Shell syntax like pipes, redirects, and && chains works.
Parameters
scriptstring“ls -la /app && echo done”).Returns
sandbox.attachShell()
Example
Example
Returns
Stream and attach
sandbox.execStream()
Example
Example
Parameters
cmdstringargs?Iterable<string>Returns
sandbox.execStreamWith()
Example
Example
execWith(): same configuration via ExecOptionsBuilder, but returns an ExecHandle instead of buffering output.
Parameters
cmdstringReturns
sandbox.shellStream()
Example
Example
Parameters
scriptstringReturns
sandbox.attach()
Example
Example
Ctrl+] (or configured detach keys) to disconnect without stopping the process.
Parameters
cmdstringargs?Iterable<string>Returns
sandbox.attachWith()
Example
Example
Parameters
cmdstringReturns
Types
ExecOutput
Returned by exec() · execWith() · shell() · ExecHandle.collect()
The result of a completed command execution: collected output plus exit status.| Property / Method | Type | Description |
|---|---|---|
code | number (getter) | Process exit code |
success | boolean (getter) | true when code === 0 |
status | ExitStatus (getter) | Exit status object |
stdout() | string | Collected stdout decoded as UTF-8 (lossy on invalid sequences) |
stderr() | string | Collected stderr decoded as UTF-8 (lossy on invalid sequences) |
stdoutBytes() | Uint8Array | Raw stdout bytes |
stderrBytes() | Uint8Array | Raw stderr bytes |
ExecHandle
Returned by execStream() · execStreamWith() · shellStream()
A handle to a running streaming execution. ImplementsAsyncIterable<ExecEvent> and AsyncDisposable, so it works with for await...of and await using.
| Property / Method | Type | Description |
|---|---|---|
recv() | Promise<ExecEvent | null> | Receive the next event, or null once the stream ends |
takeStdin() | Promise<ExecSink | null> | Take ownership of the stdin sink. Returns null after the first call |
wait() | Promise<ExitStatus> | Wait for the process to exit |
collect() | Promise<ExecOutput> | Drain stdout/stderr and wait for exit |
signal(signal) | Promise<void> | Send a POSIX signal (numeric) to the process |
kill() | Promise<void> | Force-terminate the process |
[Symbol.asyncIterator]() | AsyncIterator<ExecEvent> | Iterate events with for await...of |
[Symbol.asyncDispose]() | Promise<void> | Best-effort kill on await using scope exit |
ExecSink
Returned by ExecHandle.takeStdin()
Writer for sending data to a running process’s stdin. ImplementsAsyncDisposable. Obtained from ExecHandle.takeStdin() when the execution was configured with .stdinPipe().
| Method | Type | Description |
|---|---|---|
write(data) | (data: Uint8Array | string) => Promise<void> | Write bytes to the process’s stdin. Strings are UTF-8 encoded |
close() | () => Promise<void> | Send EOF. Idempotent |
[Symbol.asyncDispose]() | () => Promise<void> | Calls close() on await using scope exit |
ExecEvent
Emitted by ExecHandle
Discriminated union emitted while iterating anExecHandle. The discriminator is kind.
kind | Payload | Description |
|---|---|---|
"started" | pid: number | The process has started |
"stdout" | data: Uint8Array | A chunk of stdout data |
"stderr" | data: Uint8Array | A chunk of stderr data |
"exited" | code: number | The process has exited |
ExitStatus
Returned by ExecHandle.wait() · ExecOutput.status
The exit result of a process.| Field | Type | Description |
|---|---|---|
| code | number | Process exit code |
| success | boolean | true when code === 0 |
ExecOptionsBuilder
Used by execWith() · execStreamWith()
Fluent builder passed to the callback inexecWith(cmd, b => ...) and execStreamWith(cmd, b => ...). Every setter mutates the builder and returns it, so calls chain.
| Method | Type | Description |
|---|---|---|
arg(arg) | (arg: string) => this | Append a single argument |
args(args) | (args: string[]) => this | Append many arguments |
cwd(cwd) | (cwd: string) => this | Working directory |
user(user) | (user: string) => this | Guest user |
env(key, value) | (key: string, value: string) => this | Add a single env var |
envs(vars) | (vars: Record<string, string>) => this | Add many env vars |
timeout(ms) | (ms: number) => this | Kill the process after this many milliseconds |
stdinNull() | () => this | Connect stdin to /dev/null (default) |
stdinPipe() | () => this | Open a writable stdin pipe; read it back with ExecHandle.takeStdin() |
stdinBytes(data) | (data: Buffer) => this | Pre-supply stdin bytes and close it |
tty(enabled) | (enabled: boolean) => this | Allocate a pseudo-terminal |
rlimit(resource, limit) | (resource: RlimitResource, limit: number) => this | Set both soft and hard rlimit |
rlimitRange(resource, soft, hard) | (resource: RlimitResource, soft: number, hard: number) => this | Set distinct soft and hard rlimits |
AttachOptionsBuilder
Used by attachWith()
Fluent builder passed to the callback inattachWith(cmd, b => ...). Every setter mutates the builder and returns it, so calls chain.
| Method | Type | Description |
|---|---|---|
arg(arg) | (arg: string) => this | Append a single argument |
args(args) | (args: string[]) => this | Append many arguments |
cwd(cwd) | (cwd: string) => this | Working directory |
user(user) | (user: string) => this | Guest user |
env(key, value) | (key: string, value: string) => this | Add a single env var |
envs(vars) | (vars: Record<string, string>) => this | Add many env vars |
detachKeys(spec) | (spec: string) => this | Detach key sequence (e.g. "ctrl-]" or "ctrl-p,ctrl-q") |
rlimit(resource, limit) | (resource: RlimitResource, limit: number) => this | Set both soft and hard rlimit |
rlimitRange(resource, soft, hard) | (resource: RlimitResource, soft: number, hard: number) => this | Set distinct soft and hard rlimits |
Stdin
Produces StdinMode
Helper factory for constructing aStdinMode. Equivalent to the stdinNull / stdinPipe / stdinBytes setters on ExecOptionsBuilder.
| Method | Type | Description |
|---|---|---|
Stdin.null() | () => StdinMode | Connect stdin to /dev/null |
Stdin.pipe() | () => StdinMode | Open a writable pipe; caller writes via ExecHandle.takeStdin() |
Stdin.bytes(data) | (data: Uint8Array | string) => StdinMode | Send the given bytes (or UTF-8-encoded string) and close stdin |
StdinMode
Produced by Stdin
Discriminated union describing stdin behavior for an execution.kind | Payload | Description |
|---|---|---|
"null" | - | Stdin connected to /dev/null |
"pipe" | - | Writable pipe opened for the caller |
"bytes" | data: Uint8Array | Pre-supplied stdin bytes, then EOF |
Rlimit
Set via ExecOptionsBuilder.rlimit() · AttachOptionsBuilder.rlimit()
A POSIX resource limit applied to the process.| Field | Type | Description |
|---|---|---|
| resource | RlimitResource | Which resource is limited |
| soft | number | Soft limit |
| hard | number | Hard limit |
RlimitResource
Used by Rlimit.resource · rlimit() · rlimit()
String union naming a limitable POSIX resource.