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.
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.
(*CommandResult, error)
sbx.Commands.Start()
Start a command in the background and return a *CommandHandle immediately.
string
required
Shell command to execute.
Run().
Returns (*CommandHandle, error)
sbx.Commands.List()
List all running processes in the sandbox.
([]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.
(*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.error