Skip to main content

Commands

Module for starting and interacting with commands in the sandbox.

Constructors

Parameters
ParameterType
transportTransport
connectionConfigConnectionConfig
metadata{ version: string; }
metadata.versionstring
Returns
Commands

Methods

connect()

Connect to a running command. You can use CommandHandle.wait to wait for the command to finish and get execution results.
Parameters
ParameterTypeDescription
pidnumberprocess ID of the command to connect to. You can get the list of running commands using Commands.list.
opts?CommandConnectOptsconnection options.
Returns
Promise<CommandHandle> CommandHandle handle to interact with the running command.

kill()

Kill a running command specified by its process ID. It uses SIGKILL signal to kill the command.
Parameters
ParameterTypeDescription
pidnumberprocess ID of the command. You can get the list of running commands using Commands.list.
opts?CommandRequestOptsconnection options.
Returns
Promise<boolean> true if the command was killed, false if the command was not found.

list()

List all running commands and PTY sessions.
Parameters
ParameterTypeDescription
opts?CommandRequestOptsconnection options.
Returns
Promise<ProcessInfo[]> list of running commands and PTY sessions.

run()

Call Signature
Start a new command and wait until it finishes executing.
Parameters
ParameterTypeDescription
cmdstringcommand to execute.
opts?CommandStartOpts & objectoptions for starting the command.
Returns
Promise<CommandResult> CommandResult result of the command execution.
Call Signature
Start a new command in the background. You can use CommandHandle.wait to wait for the command to finish and get its result.
Parameters
ParameterTypeDescription
cmdstringcommand to execute.
optsCommandStartOpts & objectoptions for starting the command
Returns
Promise<CommandHandle> CommandHandle handle to interact with the running command.
Call Signature
Start a new command.
Parameters
ParameterTypeDescription
cmdstringcommand to execute.
opts?CommandStartOpts & objectoptions for starting the command. - opts.background: true - runs in background, returns CommandHandle - `opts.background: falseundefined- waits for completion, returnsCommandResult`
Returns
Promise<CommandResult | CommandHandle> Either a CommandHandle or a CommandResult (depending on opts.background).

sendStdin()

Send data to command stdin.
Parameters
ParameterTypeDescription
pidnumberprocess ID of the command. You can get the list of running commands using Commands.list.
datastring | Uint8Array<ArrayBufferLike>data to send to the command.
opts?CommandRequestOptsconnection options.
Returns
Promise<void>

Pty

Module for interacting with PTYs (pseudo-terminals) in the sandbox.

Constructors

Parameters
ParameterType
transportTransport
connectionConfigConnectionConfig
metadata{ version: string; }
metadata.versionstring
Returns
Pty

Methods

connect()

Connect to a running PTY.
Parameters
ParameterTypeDescription
pidnumberprocess ID of the PTY to connect to. You can get the list of running PTYs using Commands.list.
opts?PtyConnectOptsconnection options.
Returns
Promise<CommandHandle> handle to interact with the PTY.

create()

Create a new PTY (pseudo-terminal).
Parameters
ParameterTypeDescription
optsPtyCreateOptsoptions for creating the PTY.
Returns
Promise<CommandHandle> handle to interact with the PTY.

kill()

Kill a running PTY specified by process ID. It uses SIGKILL signal to kill the PTY.
Parameters
ParameterTypeDescription
pidnumberprocess ID of the PTY.
opts?Pick<ConnectionOpts, "requestTimeoutMs">connection options.
Returns
Promise<boolean> true if the PTY was killed, false if the PTY was not found.

resize()

Resize PTY. Call this when the terminal window is resized and the number of columns and rows has changed.
Parameters
ParameterTypeDescription
pidnumberprocess ID of the PTY.
size{ cols: number; rows: number; }new size of the PTY.
size.colsnumber-
size.rows?number-
opts?Pick<ConnectionOpts, "requestTimeoutMs">connection options.
Returns
Promise<void>

sendInput()

Send input to a PTY.
Parameters
ParameterTypeDescription
pidnumberprocess ID of the PTY.
dataUint8Arrayinput data to send to the PTY.
opts?Pick<ConnectionOpts, "requestTimeoutMs">connection options.
Returns
Promise<void>

Interfaces

CommandRequestOpts

Options for sending a command request.

Extended by

  • CommandStartOpts

Properties

requestTimeoutMs?

Timeout for requests to the API in milliseconds.
Default
If true, starts command in the background and the method returns immediately. You can use CommandHandle.wait to wait for the command to finish.

cwd?

Working directory for the command.
Default

envs?

Environment variables used for the command. This overrides the default environment variables from Sandbox constructor.
Default
{}

onStderr()?

Callback for command stderr output.
Parameters
ParameterType
datastring
Returns
void | Promise<void>

onStdout()?

Callback for command stdout output.
Parameters
ParameterType
datastring
Returns
void | Promise<void>

requestTimeoutMs?

Timeout for requests to the API in milliseconds.
Default

stdin?

If true, command stdin is kept open and you can send data to it using Commands.sendStdin or CommandHandle.sendStdin.
Default

timeoutMs?

Timeout for the command in milliseconds.
Default

user?

User to run the command as.
Default
default Sandbox user (as specified in the template)

ProcessInfo

Information about a command, PTY session or start command running in the sandbox as process.

Properties

args

Command arguments.

cmd

Command that was executed.

cwd?

Executed command working directory.

envs

Environment variables used for the command.

pid

Process ID.

tag?

Custom tag used for identifying special commands like start command in the custom template.

Type Aliases

CommandConnectOpts

Options for connecting to a command.