Prerequisites
Before you begin, ensure you have:- Docker installed and running
- Python 3.10 or higher
- OpenSandbox server installed and configured
Installation
Creating Your First Sandbox
Create a sandbox instance
Create a sandbox with the Code Interpreter image:The
create method accepts:- Image name: Docker image to use for the sandbox
- Entrypoint: Command to run when the container starts
- Environment variables: Custom environment configuration
- Timeout: Maximum sandbox lifetime
Execute commands
Use the sandbox context manager to execute shell commands:The
commands.run() method executes shell commands and returns:- stdout: Standard output from the command
- stderr: Standard error output
- exit_code: Command exit code
Complete Example
Here’s the complete working example:Expected Output
Next Steps
Code Interpreter Basics
Learn how to execute code in multiple languages
File Operations
Master file handling within sandboxes
API Reference
Explore the complete API documentation
More Examples
Browse advanced examples on GitHub