Last Verified: 2025-01-27
Package:
hopx-ai on PyPI
Overview
TheCommands 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.
command(str): Shell command to executetimeout(int, optional): Command timeout in seconds (default:30)background(bool, optional): Run in background (default:False)env(Dict[str, str], optional): Environment variables for commandworking_dir(str, optional): Working directory (default:'/workspace')
CommandResult - Command execution result with stdout, stderr, exit_code, and execution_time
Raises:
CommandExecutionError: Command execution failedTimeoutError: Command timed out
CommandResult Model
Therun() method returns a CommandResult object with:
stdout(str): Standard outputstderr(str): Standard errorexit_code(int): Exit code (0 = success)execution_time(float): Execution time in secondssuccess(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
Related Classes
- Sandbox - Main sandbox class
- Files - File operations resource
- Models - Data models including
CommandResult
See Also
- Core Concepts: Execution - Learn about code execution
- Sandbox Class - Access commands via
sandbox.commands
Related
- Running Commands - Learn about command execution
- Background Commands - Run commands in background
- API: Command Execution - VM Agent API endpoints
Next Steps
- Learn about Running Commands for synchronous execution
- Explore Background Commands for non-blocking tasks
- Review Code Execution for programmatic execution
- CLI Commands - Execute shell commands from the command line

