Getting Started with OpenSandbox: A Step-by-Step Tutorial
Learn how to install, configure, and use OpenSandbox for secure AI agent code execution with Docker, Kubernetes, Python SDK, and MCP integration.
Getting Started with OpenSandbox: A Practical Tutorial
In this tutorial, we'll walk through installing OpenSandbox, creating your first sandbox, running code in it, and integrating it with AI agents. By the end, you'll have a fully functional sandbox environment for your AI workloads.
π Want to deploy OpenSandbox yourself?
Docker configs, system requirements, and installation guides β all on one page.
View OpenSandbox Tool Page βStep 1: Installation via Docker
The quickest way to get started with OpenSandbox is using Docker. Pull the official image and start a sandbox server:
docker pull opensandbox/execd:latest
docker run -d --name opensandbox \
-p 8080:8080 \
-v ./data/opensandbox:/data \
opensandbox/execd:latest
This starts the sandbox runtime on port 8080. You can verify it's running with docker logs opensandbox.
Step 2: Python SDK Quick Start
Install the Python SDK and create your first sandbox:
pip install opensandbox
from opensandbox import SandboxClient
# Connect to your sandbox server
client = SandboxClient("http://localhost:8080")
# Create a sandbox
sandbox = client.create_sandbox(
image="python:3.11",
resources={"cpu": 1, "memory_mb": 512}
)
# Execute code
result = sandbox.run("print('Hello from OpenSandbox!')")
print(result.output) # Hello from OpenSandbox!
# Clean up
sandbox.destroy()
Step 3: Running Code Safely
OpenSandbox shines when you need to execute untrusted code safely. Here's how to use it with a coding agent:
# Execute arbitrary code with resource limits
result = sandbox.run(
code="""
import subprocess
result = subprocess.run(['ls', '-la'], capture_output=True, text=True)
print(f"Files: {result.stdout}")
""",
timeout=30, # 30-second timeout
memory_limit_mb=256
)
print(result.exit_code) # Safe execution
Step 4: Kubernetes Deployment
For production deployments, OpenSandbox supports Kubernetes with automatic pod scheduling, resource management, and horizontal scaling. The CNCF Landscape-listed project provides Helm charts for easy deployment:
helm repo add opensandbox https://opensandbox-group.github.io/helm-charts
helm install opensandbox opensandbox/opensandbox \
--set replicas=3 \
--set runtime.engine=kubernetes
Step 5: Integrating with MCP
OpenSandbox provides an MCP server that integrates seamlessly with AI agent frameworks:
# Configure your AI agent to use OpenSandbox MCP
mcp_servers:
opensandbox:
command: npx @opensandbox/mcp-server
args:
- --endpoint=http://localhost:8080
Comparison: OpenSandbox vs Other Solutions
| Feature | OpenSandbox | Docker | Firecracker |
|---|---|---|---|
| AI-native SDKs | β 6 languages | β | β |
| Kubernetes native | β | β οΈ | β οΈ |
| gVisor/Kata support | β | β | β |
| Network policies | β | β οΈ | β |
| Credential Vault | β | β | β |
Conclusion
OpenSandbox is the most complete sandbox platform for AI agents available today. With 12K+ GitHub stars, CNCF landscape listing, and a vibrant community, it's proven in production at scale. The multi-language SDKs, Kubernetes support, and strong isolation features make it an essential tool for any serious AI development workflow.
π Deploy OpenSandbox today!
Full deployment guides, Docker Compose, and system requirements on Run This Ai.
View OpenSandbox Tool Page β