Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Claude Sandbox SDK

管理 Claude Agent 沙盒服务的 CLI 工具。

安装

pip install claude-sandbox-sdk

使用

启动服务

# 前台运行
claude-sandbox start

# 后台运行
claude-sandbox start --daemon

# 指定端口
claude-sandbox start --port 8300

# 指定地址和端口
claude-sandbox start --host 127.0.0.1 --port 8300

停止服务

claude-sandbox stop

# 强制终止
claude-sandbox stop --force

重启服务

claude-sandbox restart

# 重启并更换端口
claude-sandbox restart --port 8300

# 先同步控制中台投放的资源,再重启
claude-sandbox restart --assets-dir /path/to/bundle

更新 Agent 资源与 MCP 工具

assets/media-studio-agent 与 mcp_tools.py 不再打进 wheel,由 agent 控制中台 维护和投放。控制中台把 bundle 写进沙盒后,执行:

claude-sandbox restart --assets-dir /path/to/bundle

bundle 目录结构(两种形态都接受):

<bundle>/
  .claude/agents/*.md
  .claude/skills/...
  CLAUDE.md
  settings.json
  mcp_tools.py          # 可选,只在 MCP 有变化时携带

或者把 agent 资源整体放在 <bundle>/media-studio-agent/ 下。同步规则:

  • agent 资源复制到工作目录,覆盖同名文件;
  • 上次投放、本次 bundle 已不存在的文件会被清理(只清理自己投放过的文件);
  • mcp_tools.py 安装到 ~/.claude-sandbox/runtime/mcp_tools.py,服务启动时 从这里动态加载,不放进工作目录;
  • 只带 mcp_tools.py 的 bundle 视为「仅更新 MCP」,不改动工作目录。

MCP 模块必须导出 mcp、set_client_env、_download_file、_wrap_song (与 server.py 的下载接口共用)。它是进程内加载的,因此新增第三方依赖时 需要同步更新沙盒镜像。

首次部署时必须先投放一次 mcp_tools.py,否则服务会拒绝启动。

查看状态

claude-sandbox status

查看日志

# 查看最近 50 行
claude-sandbox logs

# 实时跟踪
claude-sandbox logs --follow

# 查看最近 100 行
claude-sandbox logs --lines 100

配置

配置优先级: CLI 参数 > 环境变量 > 默认值

配置项 环境变量 默认值
host CLAUDE_SANDBOX_HOST 0.0.0.0
port CLAUDE_SANDBOX_PORT 8200
log_level CLAUDE_SANDBOX_LOG_LEVEL INFO
workspace CLAUDE_SANDBOX_WORKSPACE /home/user/workspace
mcp_path CLAUDE_SANDBOX_MCP_PATH ~/.claude-sandbox/runtime/mcp_tools.py

数据目录

服务运行时数据存储在 ~/.claude-sandbox/:

  • pid — 运行中的进程 PID
  • port — 当前使用的端口
  • server.log — 服务日志
  • runtime/mcp_tools.py — 控制中台投放的 MCP 工具模块
  • deployed_assets.json — 上次同步到工作目录的文件清单

开发

# 克隆仓库
git clone https://github.com/ai302/claude-sandbox-sdk.git
cd claude-sandbox-sdk

# 安装开发依赖
pip install -e ".[dev]"

# 运行测试
pytest

# 代码检查
ruff check .
mypy app/

发布

# 构建
python -m build

# 上传到 PyPI
twine upload dist/*

API 端点

端点 方法 说明
/health GET 健康检查
/sessions GET 列出会话
/sessions/{id} GET 获取会话信息
/sessions/{id}/messages GET 获取会话消息
/ws/chat WebSocket 聊天接口

License

MIT

Metadata

Release files for claude-sandbox-sdk 0.2.0b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for claude-sandbox-sdk 0.2.0b1
File Size Uploaded Provenance Actions
claude_sandbox_sdk-0.2.0b1.tar.gz 36.7 kB Without provenance Details for claude_sandbox_sdk-0.2.0b1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for claude-sandbox-sdk 0.2.0b1
File Interpreter ABI Platform Actions
claude_sandbox_sdk-0.2.0b1-py3-none-any.whl Python 3 none any Details for claude_sandbox_sdk-0.2.0b1-py3-none-any.whl

Total release size: 69.8 kB

Release files / claude_sandbox_sdk-0.2.0b1.tar.gz

Download URL claude_sandbox_sdk-0.2.0b1.tar.gz
Size 36.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c060c9a0c745f6d0f359b295acd4af3712dbf89a2a9523fb43dd37dd393442f6
BLAKE2b-256 checksum
How to use checksums
2e4bbf0ee99ee23f36a09a301254d3fdfae5619d69431938417a627afc8f0038
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / claude_sandbox_sdk-0.2.0b1-py3-none-any.whl

Download URL claude_sandbox_sdk-0.2.0b1-py3-none-any.whl
Size 33.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5143e2d08f6619a433d3779e175bd5d7efa333a19857c886e7c75a059e3dc52e
BLAKE2b-256 checksum
How to use checksums
e153cccd2b35bc25d9177f0af62ec57444b36cd5113e91e059faa03e70a7e304
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for claude-sandbox-sdk 0.2.0b1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page