run_command() method executes a short-lived command inside your active sandbox container and waits for it to finish before returning the output.
It’s ideal for quick, synchronous tasks such as listing files, checking Python or Node.js versions, or running lightweight scripts that complete within a few seconds.
This method captures both stdout and stderr once the command completes. Because it’s optimized for speed and simplicity, run_command() has a strict 5-second execution limit and does not support streaming output.
async run_command(cmd: str, args: Optional[List[str]] = None) -> CommandResult
Description:Executes a short command (< 5 seconds) and returns its standard output and standard error.
For longer-running or streaming processes, use
run_streaming_command() instead.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
cmd | str | Yes | Command to execute (e.g. "python3", "ls", "echo") |
args | List[str] | No | List of command arguments |
Returns:
CommandResult object with the following attributes:
stdout: str- Standard outputstderr: str- Standard errorexit_code: int- Exit code (defaults to 0)
- 5 second maximum : Command will timeout
- No streaming - must wait for completion
- Exit code is always 0 for this method (use
run_streaming_command()if you need accurate exit codes)
