Skip to content

fix: make sandbox_docker_mcp an optional extra to fix default CLI crash - #7

Closed
Ariasu123 wants to merge 1 commit into
mainfrom
refactor/decouple-sandbox-extra
Closed

fix: make sandbox_docker_mcp an optional extra to fix default CLI crash#7
Ariasu123 wants to merge 1 commit into
mainfrom
refactor/decouple-sandbox-extra

Conversation

@Ariasu123

Copy link
Copy Markdown
Owner

问题

Docker sandbox 早已抽成独立的 sandbox-docker-mcp MCP server,只有 pion mcp 子进程需要它。但它被声明为核心依赖,并在包导入时被无条件 import(sandbox/__init__.pydocker.py),导致缺包时默认 --sandbox off 也会 ModuleNotFoundError 崩溃,整个 CLI 起不来。

改动

P0 — 主进程与可选包彻底解耦

  • pyproject.toml:git 依赖从核心 dependencies 移到 [project.optional-dependencies].sandbox extra;dev 组不含它,让 CI 默认在"缺包"环境跑,作为解耦回归门。
  • pion/sandbox/__init__.py:不再 import .docker,从 __all__ 移除两个名字。主进程侧的 pion.sandbox 完全不碰外部包。
  • pion/cli/__init__.py:只导入 build_runtime
  • pion/cli/bootstrap.py:移除主进程内的 Docker 预检;改为 MCP 启动后 fail-fast——mcp 后端下 sandbox server(唯一工具来源)没连上就报错并 Exit(1)
  • pion/mcp/client.py:新增 MCPClientManager.connected_server_names
  • pion/mcp/sandbox_server.py:外部 import 下沉到 serve()/build_server_runtime(),缺包给出友好错误并退出;Docker 预检下推到该 pion mcp 子进程。

P1 — 文档

  • README.md / README.zh-CN.md:讲清主进程是 MCP client、sandbox 是可选 extra 默认不装,并给出安装命令。

测试

  • tests/test_sandbox_adapter.py:加 pytest.importorskip("sandbox_docker_mcp")
  • tests/test_cli.py:改写启动测试以覆盖新的 fail-fast 路径;新增 subprocess 回归测试,用 sys.modules['sandbox_docker_mcp']=None 模拟缺包,证明默认导入路径不需要该 extra。

验证

  • pytest:312 passed(含新回归测试)
  • demos/mock_e2e.py:MOCK E2E OK

🤖 Generated with Claude Code

The Docker sandbox already lives in the standalone sandbox-docker-mcp MCP
server, which only the `pion mcp` server child needs. But it was declared as
a core dependency and imported unconditionally at package-import time
(sandbox/__init__.py -> docker.py), so a missing package crashed the whole
CLI with ModuleNotFoundError even under the default `--sandbox off`.

Decouple the main process from the optional package entirely:

- pyproject: move the git dependency from core deps to a `sandbox` optional
  extra; the dev group excludes it so CI runs in a package-absent env as a
  decoupling regression gate.
- sandbox/__init__.py: stop importing `.docker`; drop the two names from
  __all__. The main-process `pion.sandbox` no longer touches the extra.
- cli/__init__.py: import only build_runtime.
- cli/bootstrap.py: remove the in-process Docker preflight; fail fast after
  MCP startup if the sandbox server did not connect (its only tool source).
- mcp/client.py: add MCPClientManager.connected_server_names.
- mcp/sandbox_server.py: defer the external imports into serve()/
  build_server_runtime() with a friendly ModuleNotFoundError exit, and push
  the Docker preflight down into this `pion mcp` child.

Docs: README.md / README.zh-CN.md clarify the main process is an MCP client,
the sandbox ships as an opt-in extra, and give the install commands.

Tests: importorskip the adapter suite; rewrite the CLI startup tests for the
new fail-fast path; add a subprocess regression proving the default import
path works with sandbox_docker_mcp absent.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Ariasu123 Ariasu123 closed this Aug 28, 2026
@Ariasu123
Ariasu123 deleted the refactor/decouple-sandbox-extra branch August 28, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant