claude-code
English
Sandbox runtime for Anthropic Claude Code, preinstalled with the Claude Code CLI to support AI-driven coding, debugging, and refactoring.
Environment
This template comes preinstalled with the following tools and dependencies:
| Category | Details |
|---|---|
| Base image | python:3.12-slim |
| Node.js | Node.js 22.x + npm (core runtime) |
| Python | Python 3.12 + venv (at /opt/venv) |
| Node packages | @anthropic-ai/claude-code |
| Python packages | anthropic, httpx, rich |
| System tools | git, curl, ripgrep, build-essential |
| Resources | 2 CPU / 4096 MB memory |
Installation
Install from a local path:
abx template install ./claude-code --registry-type local
Install from GitHub:
abx template install alibaba-agent-sandbox/awesome-templates//claude-code
Usage
Create a sandbox instance and pass in the API key:
abx create --template claude-code --env ANTHROPIC_API_KEY=sk-ant-xxx
Launch Claude Code inside the sandbox:
abx exec <sandbox-id> -- claude "Write a Python HTTP server"
Run a task in non-interactive mode:
abx exec <sandbox-id> -- claude -p "Refactor this function for better performance" --allowedTools "Edit,Read,Write"
Using the Python SDK:
from agent_sandbox import Sandbox
sandbox = Sandbox.create_sync(
template="claude-code",
env={"ANTHROPIC_API_KEY": "sk-ant-xxx"}
)
result = sandbox.commands.run("claude -p 'Generate a REST API scaffold'")
print(result.stdout)
Configuration
Environment Variables
| Variable | Description | Required |
|---|---|---|
ANTHROPIC_API_KEY |
Anthropic API key | Yes |
WORKSPACE |
Working directory path, defaults to /workspace |
No |
Custom Configuration
To install extra dependencies on top of this template, run the following after the sandbox is created:
abx exec <sandbox-id> -- pip install <package-name>
abx exec <sandbox-id> -- npm install -g <package-name>
Notes
- API key security: Never hardcode
ANTHROPIC_API_KEYinto the template; always inject it via the--envoption or environment variables. - Network access: Claude Code needs to reach the Anthropic API — make sure the sandbox has outbound internet connectivity.
- Node.js is the core runtime: The Claude Code CLI runs on Node.js; Node.js 22 is a core dependency.
- Resource usage: AI code-generation tasks may consume significant memory; keeping 4096 MB or more is recommended.
- Virtual environment: Python packages are installed in
/opt/venv; no manual activation is needed sincePATHis preconfigured.
中文
Anthropic Claude Code 的沙箱运行环境,预装 Claude Code CLI,支持 AI 驱动的代码编写、调试和重构。
环境说明
本模板预装以下工具和依赖:
| 类别 | 内容 |
|---|---|
| 基础镜像 | python:3.12-slim |
| Node.js | Node.js 22.x + npm(核心运行时) |
| Python | Python 3.12 + venv 虚拟环境(位于 /opt/venv) |
| Node 包 | @anthropic-ai/claude-code |
| Python 包 | anthropic、httpx、rich |
| 系统工具 | git、curl、ripgrep、build-essential |
| 资源配置 | 2 CPU / 4096 MB 内存 |
安装方式
从本地安装:
abx template install ./claude-code --registry-type local
从 GitHub 安装:
abx template install alibaba-agent-sandbox/awesome-templates//claude-code
使用示例
创建沙箱实例并传入 API Key:
abx create --template claude-code --env ANTHROPIC_API_KEY=sk-ant-xxx
在沙箱中启动 Claude Code:
abx exec <sandbox-id> -- claude "编写一个 Python HTTP 服务器"
非交互模式执行任务:
abx exec <sandbox-id> -- claude -p "重构这个函数以提高性能" --allowedTools "Edit,Read,Write"
使用 Python SDK:
from agent_sandbox import Sandbox
sandbox = Sandbox.create_sync(
template="claude-code",
env={"ANTHROPIC_API_KEY": "sk-ant-xxx"}
)
result = sandbox.commands.run("claude -p '生成一个 REST API 框架'")
print(result.stdout)
配置说明
环境变量
| 变量名 | 说明 | 必填 |
|---|---|---|
ANTHROPIC_API_KEY |
Anthropic API 密钥 | 是 |
WORKSPACE |
工作目录路径,默认 /workspace |
否 |
自定义配置
如需在模板基础上安装额外依赖,可在创建沙箱后执行:
abx exec <sandbox-id> -- pip install <package-name>
abx exec <sandbox-id> -- npm install -g <package-name>
注意事项
- API Key 安全:请勿将
ANTHROPIC_API_KEY硬编码到模板中,始终通过--env参数或环境变量注入。 - 网络访问:Claude Code 需要访问 Anthropic API,确保沙箱具备外网连接能力。
- Node.js 核心:Claude Code CLI 基于 Node.js 运行,Node.js 22 为核心依赖。
- 资源消耗:AI 代码生成任务可能消耗较多内存,建议保持 4096 MB 以上的内存配置。
- 虚拟环境:Python 包安装在
/opt/venv中,使用时无需手动激活,PATH已自动配置。
Deploy and local e2e
Install and register this template:
abx template install alibaba-agent-sandbox/awesome-templates//claude-code
From this directory (build, push, and register):
abx deploy
From the repository root, with agent-sandbox-server and httpx installed:
python3 scripts/run_local_e2e.py
That starts python3 commands.py in this directory and runs e2e_test.py.