by alibaba
Secure, Fast, and Extensible Sandbox runtime for AI agents.
# Add to your Claude Code skills
git clone https://github.com/alibaba/OpenSandboxOpenSandbox is a general-purpose sandbox platform for AI applications, offering multi-language SDKs, unified sandbox APIs, and Docker/Kubernetes runtimes for scenarios like Coding Agents, GUI Agents, Agent Evaluation, AI Code Execution, and RL Training.
OpenSandbox is now listed in the CNCF Landscape.
Requirements:
uv pip install opensandbox-server
opensandbox-server init-config ~/.sandbox.toml --example docker
If you prefer working from source, you can still clone the repo for development, but you no longer need to clone this repository just to start the server. You'll also require an instance of docker running.
git clone https://github.com/alibaba/OpenSandbox.git && cd OpenSandbox/server cp opensandbox_server/examples/example.config.toml ~/.sandbox.toml uv sync && uv run python -m opensandbox_server.main
opensandbox-server
# Show help
# opensandbox-server -h
Install the Code Interpreter SDK
uv pip install opensandbox-code-interpreter
Create a sandbox and execute commands and codes.
import asyncio
from datetime import timedelta
from code_interpreter import CodeInterpreter, SupportedLanguage
from opensandbox import Sandbox
from opensandbox.models import WriteEntry
async def main() -> None:
# 1. Create a sandbox
sandbox = await Sandbox.create(
"opensandbox/code-interpreter:v1.0.2",
entrypoint=["/opt/opensandbox/code-interpreter.sh"],
env={"PYTHON_VERSION": "3.11"},
timeout=timedelta(minutes=10),
)
async with sandbox:
# 2. Execute a shell command
execution = await sandbox.commands.run("echo 'Hello OpenSandbox!'")
print(execution.logs.stdout[0].text)
# 3. Write a file
await sandbox.files.write_files([
WriteEntry(path="/tmp/hello.txt", data="Hello World", mode=644)
])
# 4. Read a file
content = await sandbox.files.read_file("/tmp/hello.txt")
print(f"Content: {content}") # Content: Hello World
# 5. Create a code interpreter
interpreter = await CodeInterpreter.create(sandbox)
# 6. Execute Python code (single-run, pass language directly)
result = await interpreter.codes.run(
"""
import sys
print(sys.version)
result = 2 + 2
result
""",
language=SupportedLanguage.PYTHON,
)
print(result.result[0].text) # 4
print(result.logs.stdout[0].text) # 3.11.14
# 7. Cleanup the sandbox
await sandbox.kill()
if __name__ == "__main__":
asyncio.run(main())
OpenSandbox provides examples covering SDK usage, agent integrations, browser automation, and training workloads. All example code is located in the examples/ directory.
For more details, please refer to examples and the README files in each example directory.
| Directory | Description |
|-----------|------------------------------------------------------------------|
| sdks/ | Multi-language SDKs (Python, Java/Kotlin, TypeScript/JavaScript, C#/.NET) |
| specs/ | OpenAPI specs and lifecycle specifications |
| server/ | Python FastAPI sandbox lifecycle server |
| kubernetes/ | Kubernetes deployment and examples |
| components/execd/ | Sandbox execution daemon (commands and file operations) |
| components/ingress/ | Sandbox traffic ingress proxy |
| components/egress/ | Sandbox network egress control |
| sandboxes/ | Runtime sandbox implementations |
| examples/ | Integration examples and use cases |
| [oseps/](os
No comments yet. Be the first to share your thoughts!