Skip to content

fix(sandbox): pin writable ancestors of nested protected skill mounts - #180840

Merged
eleqtrizit merged 5 commits into
openclaw:mainfrom
eleqtrizit:1119
Oct 26, 2026
Merged

eleqtrizit merged 5 commits into
openclaw:mainfrom
eleqtrizit:1119

Conversation

@eleqtrizit

@eleqtrizit eleqtrizit commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

With workspaceAccess: "rw" (and private "none" workspaces), OpenClaw bind-mounts skill roots read-only at nested paths inside the writable workdir (<workdir>/.agents/skills, <workdir>/.openclaw/sandbox-skills/skills). Linux refuses to rename a mountpoint, but not its parent, so a sandboxed shell could move .agents or .openclaw aside and recreate the protected skill path as ordinary writable files. This PR binds each writable directory between the workdir and a nested protected mount onto itself, so those parents are mountpoints too and the rename fails with EBUSY. It complements #96028 and #126775, which handle different layers.

What Problem This Solves

The docs promise that "local container mounts and sandbox file tools enforce these read-only roots." The sandbox file tools already refuse to rename a parent of a read-only mount (requireWritable: "subtree" in src/agents/sandbox/fs-bridge-mutation-helper.ts). Shell exec does not go through that check, so the sandboxed model could still replace a protected skill path:

  • .agents/skills: the replacement lands in the host workspace. Host skill discovery picks it up, it can shadow a lower-precedence skill with the same name, and the next container recreate mounts the agent-written copy read-only.
  • Materialized .openclaw/sandbox-skills/skills: exec and skill scripts inside the sandbox see the agent's copy instead of the managed one.

After this change, a sandboxed process cannot move those parent directories, so the protected path keeps resolving to the real read-only mount. Ordinary edits to other files in those directories still work.

What was wrong

  1. src/agents/sandbox/workspace-mounts.ts (resolveReadOnlyWorkspaceSkillMounts) plans protected mounts at nested container paths, but nothing pins the intermediate directories (.agents, .openclaw, .openclaw/sandbox-skills). They stay ordinary entries inside the writable workspace bind.
  2. src/agents/sandbox/mount-plan.ts (prepareSandboxMountPlan) emits only the workspace and protected-leaf binds, so in the created container those parents can be renamed by any sandboxed process.

Net effect: a sandboxed exec could detach the read-only mount and put agent-written instructions at the protected path.

Why this design

  • Pin the parents at the owning boundary, the container mount plan, so the kernel enforces it for every in-container process and not only the file tools.
  • Work out the parents generically from the planned mounts (workdir, owning managed mount, protected target). Nothing is hardcoded to .agents or /workspace, so non-default workdirs are covered.
  • Pin only parents owned by a managed workspace or agent mount that is writable. Read-only roots already refuse the rename, and custom binds keep their daemon-host contract.
  • Skip the pin when a Docker-hosted Gateway already exposes that parent through its own read-only bind. That bind is projected as its own mountpoint, and its writable child binds keep their access. A read-only parent cannot be renamed anyway.
  • Create the parent directories on the host before the container is created, as the workspace owner, through the existing fs-safe root (mutationSymlinks: "reject", assertCurrent). Engines can't create them root-owned, and a symlinked parent fails closed.
  • Send the self-binds through the existing translateSandboxMountSources path, so Gateway-in-Docker deployments translate them like any other managed bind. Each one is ordered before the protected mount it pins.
  • Teach the image-backing check (sandboxContainerShowsWorkspacePaths) to accept a covering self-bind only when its source is the workspace source at that same relative path, so images under .agents/ still display and unrelated binds are still rejected.
  • No config surface or default change. Existing containers pick up the new binds through the existing config-hash and sandboxMountPlanMatchesContainer mount-change handling.

Why this does not conflict with related PRs

PR Governed layer Relation to this PR
#85591 (merged) Introduced read-only skill mounts This PR closes the parent-rename gap left in that layout
#96028 (open) Creating missing protected skill roots Different concern (roots that don't exist yet); both create directories before the container, in different helpers
#126775 (open) Moving the materialized skills mount to a direct workdir child Would remove one nested target; .agents/skills stays nested and still needs this pinning. The two compose: if the materialized target becomes a direct child, no parent bind is produced for it

Evidence of Fix

Both runs created the sandbox through OpenClaw's own ensureSandboxContainer (rw workspace, shared scope, openclaw-sandbox:bookworm-slim, Docker 29.8.0), then ran commands with docker exec as the sandbox user (uid 1000). The host workspace held an inert SKILL.md marker with description: ORIGINAL.

Path Before (upstream main 5730de35ae9) After (this branch)
Mounts OpenClaw created (docker inspect) /workspace rw, /workspace/.agents/skills ro, /workspace/.openclaw/sandbox-skills/skills ro the same, plus rw self-binds at /workspace/.agents, /workspace/.openclaw, /workspace/.openclaw/sandbox-skills
mv /workspace/.agents … exit 0 Device or resource busy, exit 1
Recreate .agents/skills/demo/SKILL.md exit 0; host marker becomes REPLACED not reachable; host marker stays ORIGINAL
mv /workspace/.openclaw … exit 0 Device or resource busy, exit 1
mv /workspace/.openclaw/sandbox-skills … not run refused (Read-only file system on the protected child), exit 1
Write inside a protected skill root blocked (not re-run) Read-only file system, exit 1
Sibling writes in .agents/ and .openclaw/ allowed allowed, exit 0
Captured terminal output (scratch paths redacted)
## BEFORE (upstream main 5730de35ae9) docker 29.8.0 container=proof1119-shared (created by ensureSandboxContainer)
## docker inspect .Mounts
/workspace rw=true
/workspace/.agents/skills rw=false
/workspace/.openclaw/sandbox-skills/skills rw=false
## exec as sandbox user
1000
mv .agents exit=0
recreate protected path exit=0
mv .openclaw exit=0
## host marker
description: REPLACED
## docker 29.8.0  container=proof1119-shared (created by ensureSandboxContainer)
## docker inspect .Mounts
/workspace rw=true
/workspace/.agents rw=true
/workspace/.openclaw rw=true
/workspace/.agents/skills rw=false
/workspace/.openclaw/sandbox-skills rw=true
/workspace/.openclaw/sandbox-skills/skills rw=false

## exec as sandbox user
1000
mv: cannot move '/workspace/.agents' to '/workspace/moved': Device or resource busy
mv .agents exit=1
mv: cannot move '/workspace/.openclaw' to '/workspace/moved': Device or resource busy
mv .openclaw exit=1
mv: cannot remove '/workspace/.openclaw/sandbox-skills/skills/demo/SKILL.md': Read-only file system
mv .openclaw/sandbox-skills exit=1
touch: cannot touch '/workspace/.agents/skills/x': Read-only file system
write protected skill exit=1
sibling writes exit=0
description: ORIGINAL
## host marker
description: ORIGINAL

Podman was not run locally. The reporter measured the same mount layout working on rootless Podman 6.1.3.

Testing

  • New tests in src/agents/sandbox/mount-plan.test.ts:
    • parents pinned under a non-default workdir, with host directories created as the workspace owner and ordered before the mounts they pin;
    • a read-only Gateway parent bind stays read-only instead of failing startup, and a writable Gateway child below it stays writable;
    • a container created before this fix is detected as a mount change;
    • a symlinked parent is refused, with nothing created outside the workspace;
    • no parent binds under a read-only workspace;
    • image-backing reads under a pinned parent accept the matching self-bind and reject a different source.
  • Updated the existing whitespace plan expectations to include the parent binds.
  • pnpm vitest run src/agents/sandbox/: 56 files, 698 passed, 3 skipped.
  • pnpm tsgo:core passes; oxlint and oxfmt are clean on the changed files.

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 22, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR pins writable parent directories of protected skill mounts so sandbox processes cannot move them aside and replace protected paths.

Example: A Docker sandbox running as UID 1000 has workspaceAccess="rw" and an existing /workspace/.agents/skills/demo/SKILL.md.

  • Before: Moving /workspace/.agents succeeds, and recreating the skill path changes the host marker from ORIGINAL to REPLACED.
  • After: Moving /workspace/.agents fails with EBUSY, the host marker remains ORIGINAL, and ordinary sibling writes still succeed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused protection with real kernel-enforcement evidence and no remaining introduced findings; draft status and skipped broad CI still defer landing.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied production-owner Docker run creates real sandboxes through ensureSandboxContainer and exercises final filesystem effects as UID 1000: ancestor renames and protected writes fail, sibling writes succeed, and the host marker stays intact; the latest Gateway permission repair has focused regression coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Sandbox shell commands can replace skill paths documented as read-only by moving their writable parent directories.
Reason: The demonstrated bypass violates an existing protection contract, and the fix uses the owning mount boundary without adding configuration or a competing implementation.

Merge readiness

✅ Ready for maintainer review

This PR fixes a demonstrated read-only skill protection bypass that remains on main and in the latest release; the previous writable-child finding is resolved, with no remaining introduced defect identified.

Priority: P1
Reviewed head: 1b7ffaf2668e78520cf2a270b195d59ef1676725

Before merge

None.

Findings

None.

Agent review details

How this fits together

The sandbox mount planner turns workspace paths, protected skill roots, Gateway mount metadata, and custom binds into container mounts used by shell and browser runtimes and checked by workspace image readers.

flowchart TD
 A[Workspace and protected skill roots] --> B[Existing mount selection]
 B --> C[Ancestor pins and source translation]
 C --> D[Docker or Podman container]
 D --> E[Kernel enforces protected paths]
 C --> F[Workspace image backing validation]
Loading

Technical review

Best possible solution:

Use the existing mount planner to pin writable ancestors while preserving Gateway child permissions and exact workspace backing identity.

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

The supplied before/after Docker trace demonstrates the parent-rename bypass, and current-main source retains the same vulnerable mount layout; this read-only review did not execute target code.

Is this the best way to solve the issue?

The fix enforces the existing read-only contract at the kernel mount boundary, reuses source translation and lifecycle owners, and includes the image-backing adjustment needed by the new mounts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 371306818eb6.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current main and release still lack ancestor pins: The affected production files are unchanged between the pinned merge base and fetched main; v2026.10.6 also constructs the workspace and protected-leaf mounts without ancestor self-binds. (src/agents/sandbox/mount-plan.ts:70, 371306818eb6)
  • Existing documented protection contract: The workspace-access documentation promises that local container mounts and sandbox file tools enforce read-only skill roots: https://docs.openclaw.ai/gateway/sandboxing/workspace-access. (docs/gateway/sandboxing/workspace-access.md:215, 1b7ffaf2668e)
  • Previous writable-child finding resolved: Compared with the previously reviewed head, the latest commit skips ancestors already covered by read-only Gateway mounts, allowing the existing workspace projection to retain independently writable children; a focused regression covers .agents/output. (src/agents/sandbox/mount-plan.ts:85, 1b7ffaf2668e)
  • Real Docker enforcement evidence: The supplied PR body, sourceRevision 606d063e67d892cecf9a9268c9d74284cdcd92598c3546dcdc5998deef3ef7a2, records containers created through ensureSandboxContainer on Docker 29.8.0, followed by real UID-1000 rename and write attempts: parent moves fail, protected writes fail, sibling writes succeed, and the host marker remains ORIGINAL. (1b7ffaf2668e)
  • Existing ownership and authorization retained: Ancestor allocation uses the existing fs-safe root with symlink rejection and assertBeforeMutation; mount translation remains with the existing source owner, while image reads still require matching backing sources and current authority. (src/agents/sandbox/mount-plan.ts:91, 1b7ffaf2668e)
  • Deliberate compatibility behavior: The PR explicitly chooses symlink rejection and the existing mount-change recovery contract: mismatched hot containers are preserved and report a scoped recreation command; read-only Gateway ancestors and their writable children retain their access modes. (src/agents/sandbox/current-config.ts:34, 1b7ffaf2668e)

Likely related people:

  • Jason O'Neal: Raw commit 1b7bf4a adds src/agents/sandbox/workspace-mounts.ts:38 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1b7bf4a56f9c; files: src/agents/sandbox/workspace-mounts.ts)
  • Peter Steinberger: Raw commit 0d4eb03 adds src/agents/sandbox/workspace-mounts.ts:83 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0d4eb03c0357; files: src/agents/sandbox/workspace-mounts.ts)

PR surface

Source +141, Tests +118. Total +259 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 144 3 +141
Tests 1 118 0 +118
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 262 3 +259

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +144/-3 lines; tests +118/-0 lines Growth implements ancestor discovery, safe directory preparation, mount projection, and backing identity checks within existing owners, with regressions for distinct affected boundaries.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: A sandbox process can replace paths intended to contain read-only skill instructions, including instructions subsequently discovered on the host.
  • merge-risk: 🚨 compatibility: New bind mounts trigger existing retained-container recreation handling, and symlinked ancestors are deliberately rejected; these operator-visible tradeoffs are recorded in the PR.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-22T17:56:01.422Z sha f4b4880737384c838d357c331d95ee77a1bb92c5 :: needs real behavior proof before merge. :: [P1] Preserve read-only Gateway permissions on ancestor mounts | [P2] Recognize ancestor self-binds in image backing validation
  • reviewed 2026-10-23T05:42:47.245Z sha d972e1bdbcf387a15d8d332407dfc6c9ab2fb7a9 :: needs changes before merge. :: [P1] Preserve writable Gateway children beneath read-only ancestor pins
  • reviewed 2026-10-23T05:49:10.358Z sha d972e1bdbcf387a15d8d332407dfc6c9ab2fb7a9 :: needs changes before merge. :: [P1] Preserve writable Gateway children beneath read-only ancestor pins

Reviewed October 23, 2026, 2:01 AM ET / 06:01 UTC (Revision 4).

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 23, 2026
@eleqtrizit

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 23, 2026
@clawsweeper clawsweeper Bot removed the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 23, 2026
@eleqtrizit
eleqtrizit marked this pull request as ready for review October 26, 2026 19:58
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 50de09837da8ac74bb91bf37c62973308f21dd5f
  • Maintainer: @eleqtrizit
  • Repository role: maintain

These security sensitive changes were made:

  • src/agents/sandbox/mount-plan.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/workspace-mounts.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@eleqtrizit

Copy link
Copy Markdown
Contributor Author

Merge record

Summary: Sandboxed shells could rename the parent directory of a nested read-only skill mount (e.g. $ mv /workspace/.agents …) and recreate the protected skill path as ordinary writable files, defeating the documented read-only skill protection on the exec path. This PR bind-mounts each writable ancestor between the workdir and a protected skill mount onto itself, so those parents are mountpoints and the rename fails with EBUSY while ordinary sibling writes keep working. Retained containers upgrade cleanly: revisions during review preserved read-only Gateway layouts, their writable children, image backing, and the auto-replace path for added protected mounts.

Decision Reason for Merge: Merged because the user, who is the repository maintainer, directed the merge after Clawsweeper found no actionable findings across three review rounds (final rating Platinum 4/6, "Ready for maintainer review", "Before merge: None"). The bypass was reproduced in a container created by OpenClaw's own ensureSandboxContainer on upstream main (ancestor rename exit 0, host skill marker REPLACED) and is blocked on this branch (EBUSY on all ancestor renames, marker unchanged, sibling writes succeed).

Compatibility Checks Done: Two compatibility passes were performed and recorded in the worklog: the first before shipping (no config, schema, default, or public SDK change; 3 files), re-run at the final loop state after the two review-driven fixes (both reduce compatibility risk: read-only Gateway submounts keep starting, images under pinned parents keep displaying, writable Gateway children beneath a read-only ancestor stay writable). Round-3 review confirmed no remaining introduced regressions. Locally on the final head: sandbox suite green (728 passed, 4 skipped), tsgo:core clean, oxlint/oxfmt clean, line-cap ratchet clean; hosted CI on the final head is fully green (65 passed, 0 failed, remaining checks skip this change's paths).

@eleqtrizit
eleqtrizit merged commit 321d6c6 into openclaw:main Oct 26, 2026
121 checks passed
@eleqtrizit
eleqtrizit deleted the 1119 branch October 26, 2026 21:35
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…openclaw#180840)

* fix(sandbox): pin writable ancestors of nested protected skill mounts

* fix(sandbox): keep Gateway access and image backing for pinned ancestors

* fix(sandbox): leave read-only Gateway ancestors unpinned so writable children keep access

* fix(sandbox): treat added ancestor pins as upgrade-safe protected mounts

* fix(sandbox): track pinned ancestors by container target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant