sbx.commands is the Commands instance available on every Sandbox. It provides methods to run commands, stream output, and manage processes.
sbx.commands.run()
Run a command in the sandbox. Returns a CommandResult when run in the foreground (default), or a CommandHandle when background: true.
Shell command to execute inside the sandbox.
Optional run configuration.
RunOpts
When
true, returns a CommandHandle immediately. When false (default),
blocks and returns CommandResult.Environment variables for the command.
Unix user to run the command as.
Working directory.
Command execution timeout in seconds.
Per-request HTTP timeout in milliseconds.
Callback invoked for each stdout line after the command completes
(foreground only). For real-time output, use
runStream().Callback invoked for each stderr line after the command completes.
Promise<CommandResult> (foreground) or Promise<CommandHandle> (background)
sbx.commands.runStream()
Run a command with real-time SSE streaming. Callbacks are invoked as each chunk of output arrives via Server-Sent Events.
Shell command to execute.
Optional streaming configuration.
RunStreamOpts
Environment variables for the command.
Unix user to run as.
Working directory.
Command execution timeout in seconds.
Called in real-time for each stdout chunk as it arrives.
Called in real-time for each stderr chunk as it arrives.
Promise<CommandResult> with the accumulated stdout and stderr.
sbx.commands.list()
List all running processes in the sandbox.
Per-request HTTP timeout in milliseconds.
Promise<ProcessInfo[]>
sbx.commands.kill()
Send SIGKILL to a process by PID.
Process ID to kill.
Per-request HTTP timeout in milliseconds.
Promise<boolean> — true if killed, false if already dead.
sbx.commands.sendStdin()
Write data to the stdin of a running process.
Process ID of the running command.
Data to write to stdin. Include
\n for newlines.Per-request HTTP timeout in milliseconds.
Promise<void>
sbx.commands.connect()
Create a CommandHandle for an already-running process by PID without making an API call.
Process ID of the running command.
CommandHandle (synchronous, no API call)
CommandHandle
Returned bycommands.run({ background: true }) and commands.connect().
handle.wait()
Wait for the background command to complete.
Called for each stdout line.
Called for each stderr line.
Promise<CommandResult>. Throws CommandExitError if exit code is non-zero.
handle.kill()
Kill the process.
Returns Promise<boolean>
handle.disconnect()
Disconnect from the handle (currently a no-op; reserved for future WebSocket support).
Returns void
handle.pid
Type number — the process ID.