Skip to content

feature: 新增 Cube/E2B 沙箱代码执行器与工作空间运行时#55

Merged
raychen911 merged 7 commits into
trpc-group:mainfrom
leeyyi:feat/cube-code-executor
May 9, 2026
Merged

feature: 新增 Cube/E2B 沙箱代码执行器与工作空间运行时#55
raychen911 merged 7 commits into
trpc-group:mainfrom
leeyyi:feat/cube-code-executor

Conversation

@leeyyi
Copy link
Copy Markdown
Contributor

@leeyyi leeyyi commented May 6, 2026

  • 在 trpc_agent_sdk.code_executors.cube 提供 CubeCodeExecutor 与 CubeWorkspaceRuntime, 复用 e2b-code-interpreter 远程沙箱; 通过 PEP 562 lazy getattr 实现按需加载, 不安装 [cube] extra 也可正常 import 包
  • 公共原语 CubeSandboxClient 集中封装沙箱生命周期 (open_new/open_existing/close/destroy)、结构化命令执行 (commands_run 吞掉 CommandExitException) 与文件传输 (upload_path/download_path 自动 dispatch 文件/目录, 目录走 tar 协议保留符号链接和权限)
  • 配置按 ISP 拆分: CubeCodeExecutorConfig 只承载 sandbox/执行相关字段, CubeWorkspaceRuntimeConfig 只承载 workspace 相关字段; create_cube_workspace_runtime 通过可选 workspace_cfg 注入
  • 提供 examples/code_executors/cube_demo.py 端到端示例并在 pyproject.toml 增加 [cube] 可选依赖组

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

❌ Patch coverage is 99.87390% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@1b5d226). Learn more about missing BASE report.

Files with missing lines Patch % Lines
trpc_agent_sdk/code_executors/cube/_sandbox.py 99.18699% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main         #55   +/-   ##
==========================================
  Coverage        ?   87.10260%           
==========================================
  Files           ?         389           
  Lines           ?       36550           
  Branches        ?           0           
==========================================
  Hits            ?       31836           
  Misses          ?        4714           
  Partials        ?           0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leeyyi
Copy link
Copy Markdown
Contributor Author

leeyyi commented May 7, 2026

I have read the CLA Document and I hereby sign the CLA

@leeyyi leeyyi force-pushed the feat/cube-code-executor branch from 83395ec to 50d8995 Compare May 7, 2026 02:15
Comment thread trpc_agent_sdk/code_executors/utils/_collect.py Outdated
Comment thread trpc_agent_sdk/code_executors/__init__.py Outdated
Comment thread trpc_agent_sdk/code_executors/utils/_collect.py Outdated
Comment thread trpc_agent_sdk/code_executors/utils/_collect.py Outdated
Comment thread trpc_agent_sdk/code_executors/cube/_code_executor.py Outdated
Comment thread trpc_agent_sdk/code_executors/cube/_sandbox.py Outdated
Comment thread trpc_agent_sdk/code_executors/cube/_runtime.py
Comment thread trpc_agent_sdk/code_executors/__init__.py Outdated
Rook1ex added a commit to trpc-group/cla-database that referenced this pull request May 9, 2026
leeyyi and others added 7 commits May 9, 2026 14:35
- 在 trpc_agent_sdk.code_executors.cube 提供 CubeCodeExecutor 与 CubeWorkspaceRuntime, 复用 e2b-code-interpreter 远程沙箱; 通过 PEP 562 lazy __getattr__ 实现按需加载, 不安装 [cube] extra 也可正常 import 包
- 公共原语 CubeSandboxClient 集中封装沙箱生命周期 (open_new/open_existing/close/destroy)、结构化命令执行 (commands_run 吞掉 CommandExitException) 与文件传输 (upload_path/download_path 自动 dispatch 文件/目录, 目录走 tar 协议保留符号链接和权限)
- 配置按 ISP 拆分: CubeCodeExecutorConfig 只承载 sandbox/执行相关字段, CubeWorkspaceRuntimeConfig 只承载 workspace 相关字段; create_cube_workspace_runtime 通过可选 workspace_cfg 注入
- 提供 examples/code_executors/cube_demo.py 端到端示例并在 pyproject.toml 增加 [cube] 可选依赖组

Co-authored-by: Cursor <cursoragent@cursor.com>
主要变更(按评审意见整理):

- code_executors 父包不再 lazy 重导出 Cube 符号;业务方需显式
  `from trpc_agent_sdk.code_executors.cube import ...`,让 [cube]
  依赖在调用点显性暴露,避免错把可选依赖伪装成核心依赖。
- 移除 cube 子包"未装 [cube] 也能 import"的隐含契约:
  `cube/_e2b.py` 删除,`_sandbox.py` / `_code_executor.py` 改为顶层
  `import e2b_code_interpreter as e2b`;缺失 extra 时直接以
  ImportError 在 import 处失败,而非延迟到 sandbox 打开时。
- 工作空间收集流水线:删除 utils/_collect.py,将
  `build_code_files` / `build_manifest_output` 上提为
  `BaseWorkspaceFS._build_code_files` / `._build_manifest_output`
  保护静态方法;local/container/cube 三个后端通过 self.* 调用,
  子类可直接复用或重写。`max_read_size` 由
  `Optional[int]=None` 改为 `int = MAX_READ_SIZE_BYTES`,签名更直接。
- `CubeCodeExecutor.code_block_delimiters` 改用 `default_factory`
  复用基类默认值并追加 bash fence,避免重复声明 tool_code/python;
  父类未来扩展默认列表时自动跟随。
- `cube/_runtime.py::_copy_remote`:rm -rf 调用加 Safety 注释,
  记录 normalize_remote_relative + join_remote + shell_quote +
  GNU rm `--preserve-root` 的多层校验不变量,作为后续维护合同。

测试同步:
- 新增 tests/code_executors/test_base_workspace_fs_collect.py,针对
  BaseWorkspaceFS 上的保护方法测试,并新增子类覆写用例。
- tests/code_executors/cube/conftest.py 重写 `fake_e2b` fixture,
  patch `_sandbox.e2b` / `_code_executor.e2b` 模块级符号。
- 删除 test_e2b.py、test_package_lazy_import.py,新增
  test_package_imports.py(保留父包 non-reexport + 父包 import
  不触发 e2b 的两条契约)。
- 其余测试更新 monkeypatch 目标到新的实现位置。

Assisted-by: Cursor:claude-opus-4.7
Co-authored-by: Cursor <cursoragent@cursor.com>
上一笔 refactor 移除了 cube 子包的 lazy-import 隔离层,
`trpc_agent_sdk.code_executors.cube.*` 现在在模块顶部 eager
`import e2b_code_interpreter as e2b`。CI 的 requirements-test.txt
之前没有 pin 这个 wheel(仅在 pyproject 的 [cube] extra 里声明),
导致整个 tests/code_executors/cube/ 目录在 collection 阶段
ModuleNotFoundError 失败。这里把 e2b-code-interpreter 显式列入
测试依赖,使 CI 能正常采集并运行 cube 单测。

Assisted-by: Cursor:claude-opus-4.7
Co-authored-by: Cursor <cursoragent@cursor.com>
CI 的 yapf lint 在三处与本仓库的 [tool.yapf]
(based_on_style=pep8, column_limit=120) 不一致,本提交按 yapf
建议自动修正:

- trpc_agent_sdk/code_executors/__init__.py: 删除 import 块和
  __all__ 之间的多余空行(同段跨语义边界 yapf 不允许双空行)。
- trpc_agent_sdk/code_executors/cube/_code_executor.py:
  ``Field(default_factory=...)`` 单行表达式 < 120 列,yapf 折叠
  为单行。
- trpc_agent_sdk/code_executors/local/_local_ws_runtime.py:
  超过 120 列的 ``self._build_manifest_output(...)`` 调用按 yapf
  默认风格逐参数换行。

无逻辑变更;仅排版。

Assisted-by: Cursor:claude-opus-4.7
Co-authored-by: Cursor <cursoragent@cursor.com>
- examples/skills 与 examples/skills_with_container 下示例 skill 目录改用连字符命名
- 同步更新 README、agent/tools.py、docs/mkdocs/{en,zh}/skill.md 与 openclaw/config_full.temp.yaml 中的引用
- 调整容器示例日志展示,体现 host:// / workspace:// / skill:// 三种 input scheme 全部成功落地

Assisted-by: Cursor:claude-opus-4.7
Co-authored-by: Cursor <cursoragent@cursor.com>
@leeyyi leeyyi force-pushed the feat/cube-code-executor branch from 6e9e368 to 9c7bac8 Compare May 9, 2026 06:39
@raychen911 raychen911 merged commit f421802 into trpc-group:main May 9, 2026
6 checks passed
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.

2 participants