Skip to main content
Version: 0.3.0
Last Verified: 2025-01-27
Package: hopx-ai on PyPI

Overview

The Commands resource provides shell command execution capabilities for sandboxes. Access it via the commands property on a Sandbox instance. Use this resource when you need to run shell commands, install packages, or execute system utilities. The Commands resource is lazy-loaded and provides synchronous command execution.

Access

Methods

run

Run a shell command.
Parameters:
  • command (str): Shell command to execute
  • timeout (int, optional): Command timeout in seconds (default: 30)
  • background (bool, optional): Run in background (default: False)
  • env (Dict[str, str], optional): Environment variables for command
  • working_dir (str, optional): Working directory (default: '/workspace')
Returns: CommandResult - Command execution result with stdout, stderr, exit_code, and execution_time Raises:
  • CommandExecutionError: Command execution failed
  • TimeoutError: Command timed out
Example:
See Also:

CommandResult Model

The run() method returns a CommandResult object with:
  • stdout (str): Standard output
  • stderr (str): Standard error
  • exit_code (int): Exit code (0 = success)
  • execution_time (float): Execution time in seconds
  • success (bool): Convenience property (exit_code == 0)

Examples

Example 1: Basic Command Execution

Example 2: Install Packages

Example 3: Command with Environment Variables

Example 4: Working Directory

Example 5: Long-Running Commands


  • Sandbox - Main sandbox class
  • Files - File operations resource
  • Models - Data models including CommandResult

See Also

Next Steps