refactor(sandbox): 按威胁模型精确化——仅不受信任代码进容器

http/db 类工具的子进程是瘦壳(纯计算),危险操作全在受信任主进程,
套容器是纯开销无隔离收益。调整为:

- 开发者预写工具:移除 spec 的 sandbox: profile: stdio,回默认 local
  本地执行(仍保留 env_clear + 白名单注入)
- tool_manager 产出的工具:spec_yaml 自动写 sandbox: profile: stdio,
  不受信任代码(LLM 提供 rust_code)默认进 stdio 容器
- tool_manager 编译:仍走 builder 容器
- 移除 ias-network-runner Dockerfile(当前无工具直接联网)
- executor docker 分支仅保留 stdio/builder,删 network 分支

验证:datetime 本地执行 +08:00;tool_manager 产出工具 spec 含
sandbox: profile: stdio 且容器内执行成功;25 测试通过。
This commit is contained in:
2026-06-22 16:53:36 +08:00
parent 4a5b21a69e
commit 092f3b78f2
23 changed files with 35 additions and 61 deletions
+21 -9
View File
@@ -33,12 +33,22 @@ if spec.is_high_risk() && !approved {
## 第二层:一次性 Docker 容器(隔离边界)
### 三类基础镜像
### 适用范围(按威胁模型精确化)
http/db 类工具的子进程是"瘦壳"——危险操作(联网、DB 读写)全在受信任的主进程里,
给它们套容器是纯开销,**没有隔离收益**。因此:
| 场景 | 是否容器隔离 | 原因 |
|------|------------|------|
| 开发者预写工具(weather/amap/... | ❌ 本地执行 | 子进程纯计算,危险操作在主进程 |
| tool_manager 产出的工具 | ✅ stdio 容器 | 含 LLM 提供的 rust_code,不受信任 |
| tool_manager 编译 | ✅ builder 容器 | cargo 执行任意 build script/proc macro |
### 两类基础镜像
| 镜像 | 用途 | 网络 | 文件系统 |
|------|------|------|----------|
| `ias-stdio-runner` | 普通 stdio 工具 | none | 只读根 + tmpfs /tmp |
| `ias-network-runner` | 需联网的工具(预留) | default | 只读根 + tmpfs /tmp |
| `ias-stdio-runner` | tool_manager 产出的不受信任工具 | none | 只读根 + tmpfs /tmp |
| `ias-tool-builder` | tool_manager 编译 Rust 工具 | none | 可写 /workbind mount |
构建:`docker/build-images.sh`
@@ -58,7 +68,7 @@ if spec.is_high_risk() && !approved {
```yaml
sandbox:
profile: stdio # local | stdio | network | builder
profile: stdio # local | stdio | builder
network: none # none | default
memory: 256m
cpus: "0.5"
@@ -66,7 +76,9 @@ sandbox:
read_only: true
```
默认 `profile: local`(不启用容器)。现有非 tool_manager 工具均设为 `profile: stdio`
默认 `profile: local`(不启用容器)。开发者预写工具保持默认
**tool_manager 产出的工具自动写入 `sandbox: profile: stdio`**(见 tool_manager `spec_yaml`),
不受信任代码默认进容器。
### 启用沙箱
@@ -121,9 +133,9 @@ enum ToolRunOutcome {
|------|------|
| tool_manager update 自身 | ❌ 拒绝(保留名) |
| create_tool risk_level=low | spec 强制 high |
| datetime 本地执行 | +08:00(宿主时区) |
| datetime Docker 执行 | +00:00(容器 UTC,证明确实隔离 |
| 容器残留检查 | 无(--rm 生效) |
| tool_manager 产出工具 spec | 自动含 `sandbox: profile: stdio` |
| datetime 本地执行 | +08:00宿主时区,默认不套容器) |
| tool_manager 产出工具 Docker 执行 | 容器内运行成功 |
| builder 容器编译 serde_json | ✅ 离线成功 |
| cargo test | 25 passed |
@@ -138,6 +150,6 @@ enum ToolRunOutcome {
| 5 | 修 clean_expired 并发 | ✅ |
| 6 | 三类 Docker 镜像 + sandbox spec | ✅ |
| 7 | stdio 工具迁移到一次性容器 | ✅ |
| 8 | network 工具迁移 | ⏸ 保持 stdio profile(工具走宿主代理联网,最小权限不给直接网络) |
| 8 | network 工具迁移 | ➖ 不需要:工具走宿主代理联网,子进程纯计算,套容器无隔离收益 |
| 9 | tool_manager build 迁移到 builder 容器 | ✅ |
| 10 | 结构化结果替换 is_tool_error | ✅ |