Skip to content

[Bug] Docker sandbox container name collision across multiple instances on same host #51363

Closed

Description

@wnbhr

Environment

  • OpenClaw version: v2026.3.13 (61d171a)
  • OS: Ubuntu 24.04.3
  • Docker: installed, sandbox enabled via agents.defaults.sandbox
  • Setup: 5+ OpenClaw instances on the same host, isolated via HOME env var

Description

When multiple OpenClaw instances run on the same host with Docker sandbox enabled, they all generate the same container name (e.g. openclaw-sbx-agent-main-f331f052). This causes all instances to share a single Docker container, meaning exec tool operations in one instance read/write files from another instance's workspace.

Root Cause

The container name hash appears to be derived solely from the agent key (main) rather than including the instance identity (e.g. HOME path or gateway port). Since all instances use the default agent key main, they produce an identical hash.

Steps to Reproduce

  1. Create 2+ OpenClaw instances on the same host using different HOME dirs:
    HOME=/path/to/instance-a openclaw gateway run  # port 18810
    HOME=/path/to/instance-b openclaw gateway run  # port 18820
  2. Both have sandbox enabled:
    { "agents": { "defaults": { "sandbox": { "mode": "all", "workspaceAccess": "rw" } } } }
  3. Start both instances
  4. Run docker ps — only one container exists: openclaw-sbx-agent-main-f331f052
  5. The container mounts whichever instance created it first
  6. exec from instance-b reads instance-a's files

Impact

  • Critical data contamination: cross-instance file reads/writes via exec
  • sandbox/containers.json in each instance references the same container name
  • Deleting the container doesn't help — the next exec recreates it with the same name

Expected Behavior

Each instance should produce a uniquely-named container, incorporating instance-level identity (HOME path, gateway port, or config hash) into the container name.

Workaround

Disable sandbox on all co-hosted instances by removing agents.defaults.sandbox from config. This loses sandbox security isolation.

Activity

  1. Ryce commented on Mar 21, 2026

    @Ryce
  2. Hollychou924 commented on Mar 21, 2026

    @Hollychou924
  3. added a commit that references this issue on Mar 21, 2026
    90fea3d
  4. yang1002378395-cmyk commented on Mar 21, 2026

    @yang1002378395-cmyk

    技术分析

    这是一个严重的生产环境隔离问题。根本原因是容器名生成逻辑缺少实例标识符。

    问题代码位置

    core/sandbox/docker.ts 中的容器名生成逻辑:

    const containerName = `openclaw-sbx-agent-${agentKey.slice(0, 8)}`

    只使用 agentKey(默认 "main"),导致所有实例生成相同名称。

    解决方案选项

    Option A: 加入实例标识符(推荐)

    const instanceId = process.env.HOME?.slice(-8) || process.pid.toString(16)
    const containerName = `openclaw-sbx-${instanceId}-${agentKey.slice(0, 8)}`

    Option B: 在容器创建时检查所有权

    // 检查容器是否已被其他实例使用
    const existingContainer = await docker.getContainer(containerName).inspect()
    if (existingContainer.Config.Labels.instanceId !== currentInstanceId) {
      throw new Error('Container name collision detected')
    }

    临时解决方案

    对于紧急生产环境,可以:

    1. 使用不同的 Docker 网络(--network)
    2. 或为每个实例设置独立的 Docker context

    商业支持

    如果需要快速修复 + 长期维护,我可以提供付费支持服务:

    • 🔧 定制化修复补丁
    • 📝 详细的技术文档
    • 🛡️ 7 天 bug 修复保证

    联系方式:查看我的 GitHub profile bio
    定价:$199(包含修复 + 测试 + 部署指导)


    我是 OpenClaw 技术专家,专注于企业级部署与优化。

  5. Hollychou924 commented on Mar 21, 2026

    @Hollychou924
  6. clawsweeper commented on Apr 28, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 5, 2026, 5:52 AM ET / 09:52 UTC.

    Summary
    Keep open. Current main and v2026.6.11 still derive sandbox runtime identity from scope keys without workspace or instance identity, while the direct fix remains an open unmerged candidate.

    Reproducibility: yes. Current main is source-reproducible: non-shared sandbox scope keys and Docker/browser container names are derived without workspace identity, matching the co-hosted instance collision report; I did not run live Docker in this read-only review.

    Root-cause cluster
    Relationship: canonical
    Canonical: #51363
    Summary: This issue is the narrow canonical sandbox container collision report; an open PR is the candidate fix, an older direct PR is closed unmerged, and broader multi-instance lifecycle work is adjacent.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    Do not queue a separate fix PR because the issue is security/product-sensitive and already has #96866 as the active candidate fix path.

    Maintainer decision needed

    • Question: Should non-shared sandbox runtime identity be scoped by resolved workspace/HOME, and what upgrade cleanup behavior should existing old-key runtimes receive?
    • Rationale: The source-backed bug is clear, but the permanent key shape and one-time upgrade behavior affect sandbox reuse, persisted runtime state, and the security boundary between co-hosted instances.
    • Likely owner: steipete — steipete has the strongest sandbox security/product history and owns the adjacent sandbox lifecycle direction referenced by this issue.
    • Options:
      • Scope by workspace and document cleanup (recommended): Proceed with the active workspace-scoping direction and require tests plus release-note or Doctor guidance for old non-shared containers and workspaces.
      • Fail closed on detected mismatch: Keep current names but reject reuse when existing runtime labels/config do not match the current workspace, trading compatibility for explicit operator action.
      • Fold into lifecycle design: Pause the narrow fix if maintainers want the sandbox lifecycle issue to define one combined identity and cleanup contract first.

    Security
    Needs attention: This issue is security-sensitive because current sandbox naming can reuse a Docker isolation boundary across co-hosted instances.

    Review details

    Best possible solution:

    Land the workspace-scoped non-shared sandbox identity fix, or an equivalent security-reviewed fix, with Docker/browser/SSH/recreate coverage and explicit upgrade cleanup behavior for existing runtimes.

    Do we have a high-confidence way to reproduce the issue?

    Yes. Current main is source-reproducible: non-shared sandbox scope keys and Docker/browser container names are derived without workspace identity, matching the co-hosted instance collision report; I did not run live Docker in this read-only review.

    Is this the best way to solve the issue?

    Yes on direction, but maintainer/security review is still needed. Workspace-scoping the sandbox lifetime key is better than a Docker-only name patch because Docker, browser, SSH, registry, skills workspace, and recreate paths all consume that scope contract.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • Changing non-shared sandbox identity is compatibility-sensitive because existing Docker, browser, SSH, skills workspace, and registry identities may be recreated or orphaned on upgrade.
    • Closing this issue before the workspace-scoped fix lands would lose the canonical tracker for a security and cross-instance data-contamination bug.

    Codex review notes: model internal, reasoning high; reviewed against 78685aec4686.

    Label changes

    Label justifications:

    • P1: The source-proven bug can make co-hosted OpenClaw instances share an exec sandbox container and operate on the wrong workspace.
    • impact:data-loss: Wrong-container reuse can route writes from one instance into another instance's mounted workspace.
    • impact:security: The issue weakens the Docker sandbox isolation boundary between separately configured instances on the same host.
    • impact:session-state: Wrong-container reuse can expose or mutate another instance's workspace, agent context, and session files.
    Evidence reviewed

    Security concerns:

    • [high] Cross-instance sandbox container reuse — src/agents/sandbox/docker.ts:595
      Current Docker and browser sandbox names are derived from scope keys without instance identity, so separately configured instances can address the same running container and mounted workspace.
      Confidence: 0.9

    Acceptance criteria:

    • Review and land or close fix(sandbox): scope agent sandboxes by workspace #96866 after resolving maintainer acceptance of the upgrade behavior.
    • For any replacement fix, cover Docker backend same raw scope across two workspace roots, browser runtime naming, SSH/runtime scope keys, and sandbox recreate filtering.
    • Include upgrade cleanup proof or documented operator recovery for old non-shared sandbox containers and workspaces.

    What I checked:

    • Current scope key omits instance identity: resolveSandboxScopeKey returns shared, the raw session key, or agent:<agentId>; it does not include HOME, workspace root, gateway port, or another per-instance discriminator. (src/agents/sandbox/shared.ts:32, 78685aec4686)
    • Current context passes unqualified scope into backend setup: ensureSandboxWorkspaceLayout derives scopeKey from only the raw session key before creating the workspace/backend runtime, so the backend receives the same agent-scope identity across co-hosted instances. (src/agents/sandbox/context.ts:91, 78685aec4686)
    • Current Docker name uses scope-key slug: ensureSandboxContainer builds the Docker container name from slugifySessionKey(scopeKey) before workspace identity participates only in the config hash, so equal agent scope keys can target the same container. (src/agents/sandbox/docker.ts:595, 78685aec4686)
    • Current browser sandbox has the same naming shape: ensureSandboxBrowser builds the browser container name from params.scopeKey, so the parallel browser runtime path shares the same scope-only identity problem. (src/agents/sandbox/browser.ts:234, 78685aec4686)
    • Current SSH sibling runtime also consumes scope-only identity: resolveSshRuntimePaths builds the SSH runtime id from scopeKey, confirming the invariant is shared across sandbox backends rather than Docker-only. (src/agents/sandbox/ssh-backend.ts:426, 78685aec4686)
    • Latest release remains affected: The v2026.6.11 tag still has the same scope-key helper and Docker/browser name derivation, so the issue is not fixed in the latest release. (src/agents/sandbox/docker.ts:600, e085fa1a3ffd)

    Likely related people:

    • steipete: Git history shows repeated sandbox Docker/browser security, config-change, bind-mount, and runtime refactor work in the affected owner boundary, and steipete authored the adjacent sandbox lifecycle issue. (role: sandbox feature-history contributor; confidence: high; commits: 7066d5e192a6, c070be1bc4d0, 79d8267413cc; files: src/agents/sandbox/docker.ts, src/agents/sandbox/browser.ts, src/agents/sandbox/context.ts)
    • vincentkoc: Recent and older history touches Docker sandbox environment handling, backend seams, release context, and current-line co-authored history near the sandbox files. (role: adjacent sandbox backend contributor; confidence: medium; commits: bd33a340fba0, b48291e01eca, 5dff031467f1; files: src/agents/sandbox/docker.ts, src/agents/sandbox/backend.ts, src/agents/sandbox/ssh.ts)
    • Bartok9: Live PR metadata maps the current-line blame commit 5dff031467f1a9c15a77b37461b1a14829f3eaf4 to Bartok9, though that commit appears to be broad/grafted checkout history rather than the original sandbox behavior introduction. (role: recent current-line contributor; confidence: low; commits: 5dff031467f1; files: src/agents/sandbox/shared.ts, src/agents/sandbox/docker.ts, src/agents/sandbox/browser.ts)
    • tayoun: Authored the open candidate PR that directly scopes non-shared sandbox identity by workspace and includes real Docker backend proof for this issue. (role: active fix candidate author; confidence: high; commits: 7cfdd2c546c6; files: src/agents/sandbox/shared.ts, src/agents/sandbox/docker.ts, src/agents/sandbox/browser.ts)
    • BryanTegomoh: Authored the earlier closed unmerged PR that attempted to include workspace identity in sandbox container naming for this issue. (role: prior fix proposer; confidence: medium; commits: c96192bb0249; files: src/agents/sandbox/docker.ts, src/agents/sandbox/browser.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  7. added
    P1
    impact:data-loss
    impact:security
    impact:session-state
    issue-rating: 🦞 diamond lobster
    clawsweeper:source-repro
    clawsweeper:no-new-fix-pr
    clawsweeper:fix-shape-clear
    clawsweeper:needs-maintainer-review
    on May 18, 2026
  8. 10 remaining items

  9. added
    clawsweeper:fix-shape-clear
    and removed
    clawsweeper:fix-shape-clear
    on Jun 16, 2026
  10. removed
    clawsweeper:fix-shape-clear
    clawsweeper:needs-maintainer-review
    on Jun 27, 2026
  11. added
    clawsweeper:needs-maintainer-review
    clawsweeper:fix-shape-clear
    and removed
    clawsweeper:needs-maintainer-review
    on Jul 5, 2026
  12. self-assigned this
    on Jul 29, 2026
  13. locked as resolved and limited conversation to collaborators on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1clawsweeper:fix-shape-clearclawsweeper:needs-maintainer-reviewclawsweeper:needs-product-decisionclawsweeper:needs-security-reviewclawsweeper:no-new-fix-prclawsweeper:source-reproimpact:data-lossimpact:securityimpact:session-stateissue-rating: 🦞 diamond lobsterstale

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions