feat(integration): add Claude Code MCP Server and integration guide
What this PR does
- Adds an MCP Server (9 tools) bridging Claude Code ↔ CubeSandbox via stdio
- Bilingual README with setup flow and troubleshooting
- Integration guide following docs template conventions (EN/ZH)
Verification
- Code reviewed against CubeSandbox v0.5.0 Python SDK source
- Attempted end-to-end deployment on WSL2 (Ubuntu 26.04): CubeAPI/CubeMaster/CubeProxy healthy, but Cubelet fails (workflow plugin) and network-agent SIGSEGV on the WSL2 kernel — documented as unsupported
- Full end-to-end verification requires bare-metal Linux or cloud VM with KVM
Notes
- Follows issue template: 1 agent guide + 1 runnable example + README
- Bilingual files per docs contribution requirements
PR #757 — Claude Code MCP Server — Review Summary
Overall this is a well-structured PR that adds meaningful functionality. The code is clean, the async patterns are mostly correct, and the documentation is thorough. Below are the issues worth addressing before merging.
🔴 Critical
1. TOCTOU race on _sandbox — improper lock scope (mcp_server.py:175-179)
The global _sandbox reference is read under _lock, then the lock is immediately released. All subsequent SDK calls (sb.run_code(), sb.files.read(), etc.) run outside the lock. A concurrent sandbox_destroy can call sb.kill() mid-operation, causing confusing failures or operations on a destroyed sandbox.
Fix: Either (a) hold the lock for the duration of each tool handler (acceptable for single-client MCP over stdio), or (b) add an alive-flag check before each SDK call.
2. SIGTERM/SIGINT handlers are no-ops — orphaned sandboxes (mcp_server.py:558)
loop.add_signal_handler(sig, lambda: None)
This suppresses termination signals without triggering atexit cleanup. When Claude Code kills the MCP subprocess, the sandbox MicroVM keeps running until its timeout (up to 86,400s). Install real shutdown handlers that trigger _cleanup() and stop the event loop.
🔴 Important
3. _sanitize_error leaks internal details (mcp_server.py:133-140)
The function only truncates to 500 chars — it does not strip internal URLs, hostnames, file paths, or API endpoint details. Since these errors flow back to an LLM (Claude Code), internal network topology could be surfaced to users. Add pattern-based redaction (URLs, paths) alongside truncation.
4. _cleanup() has a data race (mcp_server.py:64-71)
_cleanup() reads _sandbox and calls sb.kill() without acquiring _lock. If a tool handler is mid-operation in a thread pool worker, the cleanup could interfere. Either use a threading lock or have _main_async perform orderly shutdown instead of relying on atexit.
5. Broken link in ZH README (examples/claude-code-sandbox/README_zh.md:254)
../sdk/python/README.md resolves to examples/sdk/python/README.md (404). Should be ../../sdk/python/README.md to match the EN version.
6. Snapshot restore workflow documented but unimplemented (docs/guide/integrations/claude-code.md:234-241)
The guide documents restoring from a snapshot in a new session, but mcp_server.py has no sandbox_restore / sandbox_resume tool. Either add restore support or correct the documentation.
🟡 Moderate
7. File operations lack timeouts (mcp_server.py:432-462)
sb.files.read() and sb.files.write() have no timeout. If the sandbox is unresponsive, these hang indefinitely. Add a default timeout using asyncio.wait_for.
8. Missing WSL2 warning in ZH README (examples/claude-code-sandbox/README_zh.md:36-41)
The English README warns "WSL2 is not supported" in the prerequisites; the Chinese version omits this. Add the warning for parity.
9. sandbox_run_code timeout type mismatch (README.md, README_zh.md, docs)
Documented as integer but the MCP schema declares "type": "number" and the validator is _validate_float. Update docs to say integer or number.
🟢 Minor
- Monolithic
call_toolfunction (220-line if/elif chain across 9 tools) — extracting per-tool handlers would improve testability. - Misleading name
_sanitize_error— rename to_truncate_errorsince it does no sanitization. - Inconsistent timeout ranges:
sandbox_createmaxes at 86,400s,sandbox_run_codeat 3,600s,sandbox_run_commandat 3,600s — min values also vary (30 vs 1). Consider harmonizing.
Refs #644
Hello, thank you for your contribution! Since we have a large number of participants in this event, to speed up the PR review process, could you please attach some screenshots and logs (both are needed) showing the verification process and results for this PR? Thank you for your participation!
Hello, thank you for your contribution. Since the PR has not been verified, I will close this PR.
@fslongjin Requesting reconsideration of this PR.
This PR adds a Claude Code MCP Server with async patterns, error sanitization, and lifecycle management. The auto-review bot confirmed code quality and all its inline feedback was addressed.
I understand verification is important. However, as noted in my other PR #787, I'm working on Windows without direct KVM access. Is there:
- A way to run the MCP server verification without a full CubeSandbox cluster?
- A test environment or CI pipeline I could use?
- Someone on the team who could help with cluster-side verification?
I'm fully available to make any code changes the reviewers identify. The code itself has been reviewed by the auto-review bot and CI is green.
Co-Authored-By: Claude [email protected]