Skip to main content
The 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:
Returns: CommandResult object with the following attributes:
  • stdout: str - Standard output
  • stderr: str - Standard error
  • exit_code: int - Exit code (defaults to 0)
Example:
Limitations:
  • 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)