0–5 分钟:检查 mounts
列出 repo、config、cache、socket、browser 和 credential-related mounts。
成功标准只暴露 task-required paths;没有 home-directory 或 secret-path surprise。
Agent workspace isolation blueprint · 更新 2026-07-04
面向 coding agents 和 long-horizon agent tools 的实用 blueprint:把任务放进 disposable containers 或 devcontainers,同时避免把 container boundary 误当成绝对安全。
Container 可以让 agent work 更 disposable、更 reproducible,但前提是 host boundary 明确。一个挂载整个 home directory、暴露 Docker socket、允许 unrestricted network、继承 host credentials 和 persistent browser state 的 container,并不构成有意义的 isolation boundary。
这份 blueprint 把 local container runtimes、Dev Containers、coding agents、mise、uv 和 self-hosted agent runtimes 连成一个操作模型:只挂载 task repository,secrets 不进 image,按敏感度隔离 caches,使用专用 browser profile,限制不必要网络,记录 artifacts,并在 review 后销毁 workspace。
目标不是宣称 container 是完美 sandbox,而是把 agent runs 变成更窄、更可复现的 workspace,并明确 host escape surfaces、可 review 权限和可预测 reset path。
RepoDaily 判断
当团队需要 reproducible tools、disposable state 和更窄文件边界时,可以使用 containerized agent workspace。但只有在 host mounts、Docker/Podman sockets、credentials、browser profiles、networks、caches 和 privileged capabilities 都被明确 review 后,才可以说 isolation 有意义。
| 表面 | 推荐边界 | 危险信号 | 保留证据 |
|---|---|---|---|
| Repository | 只挂载一个 task repo 或 clean worktree | 挂载 home directory、parent monorepo、SSH directory 或无关 repos | Mount list、repo path、branch/worktree ID、clean git status |
| Container engine socket | 默认不挂载 host engine socket | Agent 能控制 sibling containers 或 host-level engine resources | Socket policy、denied path、approved exception owner |
| Secrets | 运行时注入 task-scoped short-lived secrets | Secret 被写入 image layers、env files、shell history 或 committed config | Secret name、scope、TTL、rotation owner;绝不记录 secret value |
| Package caches | 使用分离的 disposable 或 policy-owned caches | Shared cache 会跨 run 泄漏 private packages、tokens 或 poisoned artifacts | Cache path、owner、retention、cleanup proof |
| Browser state | 使用与 personal browser state 分离的专用 automation profile | Personal cookies、password manager、inbox 或 production admin sessions 可见 | Profile identity、allowed domains、reset timestamp |
| Network | 可行时使用 default-deny 或 narrow allowlist | Agent 能访问任意 internet、metadata endpoints、databases 或 internal control planes | Allowed destinations、proxy/policy log、blocked probe result |
| Toolchain | 在 project config 中 pin runtime 与 package-manager versions | Agent 安装 global tools 或静默改变 host dependencies | Image digest、devcontainer config、mise/uv lock 与 versions |
| Artifacts 与 cleanup | 导出 reviewed diffs、tests、traces 后销毁 workspace | 遗留未知 generated files、persistent logs、orphan volumes 或 stale credentials | Artifact manifest、teardown result、final host/repo status |
在给 coding agent 写权限或运行 long-horizon tools 前评分。这里评的是 boundary clarity,不是 model capability。
| 控制项 | 0 分 | 1 分 | 2 分 | Owner 问题 |
|---|---|---|---|---|
| Repo scope | Broad host mounts | Repo mount 但额外路径可见 | Single clean repo/worktree + explicit denied paths | Agent 能读哪些 host files? |
| Engine socket | Host socket mounted | 为了方便挂载,靠人工 review | No host socket 或 tightly mediated task-specific service | Agent 能创建 privileged sibling workloads 吗? |
| Secret boundary | 暴露 long-lived host secrets | Task secrets 但 TTL/rotation 较弱 | Short-lived scoped secret injection + named rotation owner | 哪些 credentials 会在 teardown 后继续存在? |
| Network policy | Unrestricted network | 有部分 proxy 或人工 domain controls | Default-deny 或针对任务的 audited allowlist | Run 能访问哪些 destinations? |
| Cache policy | 盲目共享 host/global caches | 部分 cache 已隔离 | 敏感 caches 分离、有人负责,并明确清理或保留 | 一个 run 能通过 cache state 影响另一个 run 吗? |
| Browser isolation | 暴露 personal browser profile | Dedicated profile 无限期复用 | Dedicated profile + allowed domains + reset rule | 哪些 account state 可见? |
| Reproducibility | Pet container | Dockerfile/devcontainer 存在但会 drift | Pinned image、tool versions、lockfiles 和 setup contract | 另一台机器能复现 workspace 吗? |
| Teardown | 未知的人工 cleanup | 只删 container,volumes/logs 仍在 | 自动 export artifacts,再清 container、volume、cache 和 credential | 什么证据证明 run 已经消失? |
在把 containerized workspace 称为 isolated,或把它设成 coding agents 默认环境前,先运行这组检查。
列出 repo、config、cache、socket、browser 和 credential-related mounts。
成功标准只暴露 task-required paths;没有 home-directory 或 secret-path surprise。
检查 engine socket visibility、privileged capabilities、host PID/device access 和 writable host paths。
成功标准不存在无人负责的 privileged path 可以让 agent 控制 host-level resources。
验证 task credentials、expiry、allowed destinations、blocked destinations,以及 unrelated host credentials 不可见。
成功标准Run 只通过 scoped credentials 访问 intended services。
记录 image/base identity、mise/uv/tool versions、lockfiles、setup steps 和 test command。
成功标准第二台 clean machine 不依赖 host-specific global installs 也能复现 toolchain。
查找 logs、traces、screenshots、downloads、package caches、model caches 和 browser state。
成功标准每个 persistent artifact 都有 owner、sensitivity class 和 retention rule。
Export approved artifacts、移除 workspace/container state、revoke temporary credentials,并检查剩余 volumes/caches。
成功标准有证据证明 task state 被删除或有意保留。
| 场景 | Workspace 设计 | 额外 guardrail |
|---|---|---|
| Read-only codebase analysis | Read-only repo mount、no engine socket、restricted network、disposable logs | Block writes 和 secret paths;只 export findings 与 citations |
| Small coding task | Clean worktree、只对 repo 写、pinned tools、test command、无 host home mount | Teardown 前正常 PR review,并 export diff/test artifacts |
| Browser-assisted agent task | Repo container + 专用 automation browser profile + explicit domains | 禁止 personal profile、inbox、password manager 和 production admin sessions |
| MCP-enabled coding task | One approved MCP server、scoped credential、task-specific network path | Run 后 disable/revoke MCP credential,并保留 tool trace |
| Package-manager migration | Pinned mise/uv versions、controlled package cache、仅在需要时开放 private-index scope | Review lockfile diff、install scripts、registry destinations 和 publishing credentials |
| Long-horizon self-hosted agent | Dedicated service container、bounded volumes、job queue、log retention、explicit provider keys | Task TTL、spend limits、kill switch、artifact quota 和 operator owner |
| High-risk infrastructure repo | Disposable clone、先 read-only、默认无 cloud credentials | Write、deploy、migration 或 destructive network access 需要 explicit owner approval |
挂载 Docker 或 Podman control socket 可能让 containerized agent 变成 engine-level operator。Socket access 应是 privileged exception。
Container 会继承所有 mounted host path 的敏感性。挂载整个 home directory 会破坏 narrow repo boundary。
Build args、copied env files、shell traces、transcripts 和 debug output 可能在 container deletion 后继续保留 secrets。
Language/package caches 可能保留 credentials、private package names、malicious artifacts 或 cross-task state。
如果 agent 能访问任意 internet 或 internal services,狭窄 filesystem boundary 也无法阻止 exfiltration。
Remote browser control 或 shared profiles 可能暴露高价值 session,即使代码本身在 container 内运行。
如果 containers、volumes、caches 和 credentials 永久存在,reproducibility 和 cleanup guarantee 会退化成另一个 unmanaged workstation。
Local container 仍可能在 architecture、network、kernel、storage、secrets 和 orchestration policy 上不同于 CI/production。
每个 risky task 创建 fresh worktree 或 clone,只挂载该路径,review 后删除 workspace。
先使用 read-only mount,只有 task 确实需要 code change 时才提高到 repo write access。
默认不暴露 Docker/Podman control socket;只有任务确实需要 container orchestration 且有 owner 时才做例外。
Secrets 不进 image layers 和 repository files;运行时注入 task-scoped credentials,并设置 short TTL 与 revoke path。
分开 public dependency cache、private registry cache、model cache、build cache 和 browser/profile state,让 retention 决策显式。
Run 前列出 required destinations;runtime/environment 支持时 deny 或记录其他访问。
把 image digest 或 pinned base、Dev Container config、mise tool versions 和 uv/project locks 连成一条 reproducibility chain。
销毁 workspace 前 export diff、test report、command/tool trace、citations 和 approved generated files。
给正在设计 containerized agent workspace 的团队提供简短答案。
不够。还要 review mounts、engine sockets、capabilities、network、credentials、caches、browser state 和 cleanup。Container boundary 只是一个控制层。
默认不应该。Engine control 会显著扩大 agent 权限。只有真正需要 orchestration 时,再使用更窄的 mediated service 或有记录的 exception。
只保留有明确理由的内容:reviewed source changes、test evidence、approved logs 和 policy-owned caches。Credentials 与 browser state 应有独立 reset rules。
当团队需要 reproducible project toolchain 和 editor/runtime contract 时。它仍然需要 review mounts、secrets、network access 和 host integrations。
它们可以让 language/runtime 与 Python dependency 行为在 image/workspace 内更 reproducible,减少对 mutable host-global tools 的依赖。
Feedback
匿名反馈只用于判断内容是否真正有用。