Execute a command in the sandbox.
run(
self,
command: str,
*,
timeout: int = 60,
env: Optional[dict[str, str]] = None,
cwd: Optional[str] = None,
shell: str = '/bin/bash',
on_stdout: Optional[Callable[[str], Any]] = None,
on_stderr: Optional[Callable[[str], Any]] = None,
idle_timeout: int = 300,
kill_on_disconnect: bool = False,
ttl_seconds: int = 600,
pty: bool = False,
headers: RequestHeaders = None,
wait: bool = True
) -> Union[ExecutionResult, CommandHandle]| Name | Type | Description |
|---|---|---|
command* | str | Shell command to execute. |
timeout | int | Default: 60Command timeout in seconds. |
env | Optional[dict[str, str]] | Default: NoneEnvironment variables to set for the command. |
cwd | Optional[str] | Default: NoneWorking directory for command execution. If None, uses sandbox default. |
shell | str | Default: '/bin/bash'Shell to use for command execution. Defaults to "/bin/bash". |
on_stdout | Optional[Callable[[str], Any]] | Default: NoneCallback invoked with each stdout chunk as it arrives. Blocks until the command completes and returns ExecutionResult. Cannot be combined with wait=False. |
on_stderr | Optional[Callable[[str], Any]] | Default: NoneCallback invoked with each stderr chunk as it arrives. Blocks until the command completes and returns ExecutionResult. Cannot be combined with wait=False. |
idle_timeout | int | Default: 300Idle timeout in seconds. If the command has no connected clients for this duration, it is killed. Defaults to 300 (5 minutes). Set to -1 for no idle timeout. Only applies to WebSocket execution. |
kill_on_disconnect | bool | Default: FalseIf True, kill the command immediately when the last client disconnects. Defaults to False (command continues running and can be reconnected to). |
ttl_seconds | int | Default: 600How long (in seconds) a finished command's session is kept for reconnection. Defaults to 600 (10 minutes). Set to -1 to keep indefinitely. |
pty | bool | Default: FalseIf True, allocate a pseudo-terminal for the command. Useful for commands that require a TTY (e.g., interactive programs, commands that use terminal control codes). Defaults to False. |
wait | bool | Default: TrueIf True (default), block until the command completes and return ExecutionResult. If False, return a CommandHandle immediately for streaming output, kill, stdin input, and reconnection. Cannot be combined with on_stdout/on_stderr callbacks. |