Skip to main content
sbx.Commands is the *Commands sub-object available on every Sandbox instance. It provides methods to run foreground commands, launch background processes, and list running processes.

sbx.Commands.Run()

Run a command and block until it completes, returning stdout, stderr, and exit code.
If the command exits with a non-zero code, Run returns both the *CommandResult and a *CommandExitError. You can inspect the result even on failure:
string
required
Shell command to execute inside the sandbox.
map[string]string
Additional environment variables for this command.
string
default:"server default"
Unix user to run the command as. Server defaults to "user" when not specified.
string
Working directory. Defaults to the user’s home directory.
func(string)
Callback invoked for each line of stdout after the command completes.
func(string)
Callback invoked for each line of stderr after the command completes.
(no argument)
Enables stdin for the command, allowing data to be sent via SendStdin.
time.Duration
Maximum time to wait for the command to complete.
Returns (*CommandResult, error)

sbx.Commands.Start()

Start a command in the background and return a *CommandHandle immediately.
string
required
Shell command to execute.
Options are the same as Run(). Returns (*CommandHandle, error)

sbx.Commands.List()

List all running processes in the sandbox.
Returns ([]ProcessInfo, error)

CommandHandle

CommandHandle is returned by sbx.Commands.Start(). It provides methods to wait for or kill the process.

handle.Wait()

Block until the background command completes.
Returns (*CommandResult, error) — returns *CommandExitError on non-zero exit.

handle.Kill()

Kill the process by PID.

handle.PID

Type int — the process ID.

handle.SendStdin()

Write data to the stdin of a running background process.
Not yet implemented. Returns an error until server-side support is available.
string
required
Data to write to stdin. Include \n for newlines.
Returns error

Data models

CommandResult

ProcessInfo


Examples

Run with environment variables

Run with working directory

Capture output with callbacks

Background process