Documentation Index
Fetch the complete documentation index at: https://mintlify.com/alibaba/OpenSandbox/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This example demonstrates how to run Claude Code, Anthropic’s AI coding assistant, inside an OpenSandbox environment. The integration uses the@anthropic-ai/claude-code npm package to execute AI-powered coding tasks in a secure, isolated sandbox.
Prerequisites
- OpenSandbox server running locally or remotely
- Docker with the code-interpreter image
- Anthropic API credentials
- Python with
uvpackage manager
Setup
1. Pull the Code Interpreter Image
The code-interpreter image includes Node.js, which is required for the Claude CLI:2. Start OpenSandbox Server
Initialize and start the local server:Implementation
Installation
Install the OpenSandbox Python SDK:Code Example
Here’s the complete implementation that creates a sandbox, installs Claude CLI, and runs a query:Environment Variables
Configure the integration using these environment variables:| Variable | Required | Default | Description |
|---|---|---|---|
SANDBOX_DOMAIN | No | localhost:8080 | Sandbox service address |
SANDBOX_API_KEY | No | - | API key for authentication (optional for local) |
SANDBOX_IMAGE | No | opensandbox/code-interpreter:v1.0.1 | Docker image to use |
ANTHROPIC_AUTH_TOKEN | Yes | - | Your Anthropic authentication token |
ANTHROPIC_BASE_URL | No | - | Custom API endpoint (e.g., for proxies) |
ANTHROPIC_MODEL | No | claude_sonnet4 | Model name to use |
Running the Example
Set your environment variables and run:How It Works
- Sandbox Creation: Creates an isolated container with Node.js pre-installed
- Environment Injection: Passes Anthropic credentials securely via environment variables
- CLI Installation: Installs the Claude Code CLI using npm inside the sandbox
- Command Execution: Runs Claude commands and captures output
- Cleanup: Properly terminates the sandbox instance
Key Features
- Secure Isolation: Claude runs in a containerized environment
- Environment Control: Full control over API endpoints and models
- Log Streaming: Real-time access to stdout, stderr, and error logs
- Async Support: Built with Python’s asyncio for efficient operations
Use Cases
- AI-powered code generation in isolated environments
- Automated code analysis and refactoring
- Safe execution of AI-suggested code changes
- Testing AI coding assistants in controlled environments