executeCommand
Run arbitrary shell commands in the sandbox environment.
Method signature
Parameters
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
command | string | Yes | - | The shell command to execute in the sandbox environment |
options | object | No | {} | Configuration options for command execution |
Options Object
Property | Type | Required | Default | Description |
---|---|---|---|---|
timeoutMs | number | No | - | Maximum time in milliseconds to wait for command completion |
useRepoContext | boolean | No | false | Whether to execute the command within the repository context |
background | boolean | No | false | Whether to run the command in the background (non-blocking) |
callbacks | StreamCallbacks | No | - | Streaming callbacks for real-time command output |
StreamCallbacks Interface
Property | Type | Required | Description |
---|---|---|---|
onUpdate | (message: string) => void | No | Called with streaming updates from command output |
onError | (error: string) => void | No | Called when errors occur during command execution |
Return value
Type | Description |
---|---|
Promise<AgentResponse> | Promise that resolves to the command execution results |
AgentResponse Interface
Property | Type | Description |
---|---|---|
sandboxId | string | Unique identifier for the sandbox environment |
stdout | string | Standard output from the command execution |
stderr | string | Standard error from the command execution |
exitCode | number | Exit code from the command execution (0 indicates success) |
Examples
Basic Command Execution
Command with Timeout
Background Command Execution
Command with Repository Context
Streaming Command Output
Complex Command with All Options
Error handling
The method throws errors in the following cases:
- Sandbox not available: When no active sandbox environment exists
- Command timeout: When the command exceeds the specified timeout
- Invalid command: When the command syntax is invalid or command not found
- Permission errors: When the command requires elevated permissions not available in the sandbox
- Resource limitations: When the command exceeds sandbox resource limits
Security considerations
- Commands are executed within a sandboxed environment for security
- Elevated privileges (sudo) may not be available depending on sandbox configuration
- File system access is limited to the sandbox environment
- Network access may be restricted based on sandbox configuration
Notes
- Sandbox Environment: Commands are executed within the active sandbox environment
- Working Directory: Commands execute in the sandbox’s default working directory unless
useRepoContext
is true - Environment Variables: Sandbox environment variables are available to executed commands
- Resource Limits: Commands are subject to sandbox CPU, memory, and time limitations
- Background Execution: Background commands continue running after the method returns
- Streaming Support: Real-time output streaming is available through callbacks
- Exit Codes: Standard Unix exit codes apply (0 = success, non-zero = error)