Skip to content

fix(sandbox): isolate role-required sandboxes per guest, not per agent - #130229

Merged
steipete merged 2 commits into
mainfrom
steipete/role-sandbox-per-guest
Aug 26, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/role-sandbox-per-guest

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Role-forced sandboxing (#129926) contained an untrusted guest against the Gateway host, but not against other guests.

Sandbox identity stayed agent-scoped, so on a shared agent every session collapsed onto one scope key — one container, one workspace. Two independent amplifiers made it worse: workspaceAccess: "rw" pinned the workspace to the shared agent directory regardless of scope, and scope: "shared" used a literal shared container name.

Measured before the fix, two guests on one shared agent (resolveSandboxWorkspaceLayoutPaths):

scope=agent (DEFAULT)  access=rw  -> same scope key, same workspace (/tmp/agent-workspace-shared)
scope=agent (DEFAULT)  access=ro  -> same scope key, same workspace
scope=session          access=rw  -> distinct keys but SAME workspace  (rw pins to agentWorkspaceDir)
scope=session          access=ro  -> isolated

Only one of four combinations isolated guests, and it was not the default. The authorization layer promised "edit only your own sessions" while the container layer handed every guest the same writable workspace — guest A could read and modify guest B's work.

Why This Change Was Made

A role-forced sandbox exists to contain an untrusted principal. Sharing a runtime or a writable workspace between principals defeats that, so isolation must be keyed to the principal rather than to the agent.

Role-required sessions now derive sandbox identity from the session creator (createdActor.id, already persisted): the scope key is principal-qualified. Different guests never share a container or workspace; one guest's own sessions still do — per guest, not per session, which avoids spawning a container per session while still isolating tenants.

Three supporting cuts, all scoped to role-required sessions only:

  • configured workspaceAccess: "rw" resolves to "ro" with an operator-visible warning (otherwise the workspace is pinned to the shared agent directory and principal keying is silently defeated);
  • configured scope: "shared" resolves to an effective agent scope, so the principal-qualified key actually reaches the container name;
  • a required session with no creator provenance fails closed before provisioning rather than falling back to a shared runtime.

Sessions without the requirement — maintainers, and every roles-off deployment — keep today's behavior exactly.

User Impact

  • Guests on a shared agent are now isolated from each other, which is what makes "invite guests to the team Gateway" safe.
  • Operators need no config change: the unsafe default (scope: "agent") is corrected automatically for role-required sessions.
  • The rw downgrade is surfaced, not silent — a security downgrade nobody can see is how this class of bug survives.
  • No SQLite schema, schema-version, or protocol change; createdActor already exists on the entry.

Evidence

Independent re-derivation of the layout (not the worker's report), across all three configured scopes:

{"scope":"agent",  "sameGuest_sharesContainer":true,"differentGuests_isolated":true}
{"scope":"session","sameGuest_sharesContainer":true,"differentGuests_isolated":true}
{"scope":"shared", "sameGuest_sharesContainer":true,"differentGuests_isolated":true}

Unstamped sessions keep byte-identical scope keys to current main (verified in the same run), so maintainer behavior is provably unchanged.

Regressions (each observed failing pre-fix): different guests get distinct scope key/container/workspace across agent, session and shared; same guest reuses one across all three; persisted creator identity propagates and rw resolves to ro; unstamped sessions retain writable access and gain no guest-specific fields; provisioning converts shared→effective agent scope, caps access, uses a private workspace and emits the warning; required session without creator provenance fails closed; plugin-facing workspace authority reports ro and refuses to certify a principal-shared sandbox as session-exclusive.

Validation: 131 tests across 11 files; CI=true pnpm check:changed green; fresh $autoreview clean (0.95).

LOC: production +75/−13 (net +62), tests +277/−10, docs +25.

Found while security-auditing #129926 rather than reported from production.

Role-forced sandboxing (#129926) contained a guest against the Gateway host
but not against other guests. Sandbox identity stayed agent-scoped, so every
session on a shared agent converged on one scope key, container and
workspace; configured workspaceAccess "rw" additionally pinned the workspace
to the shared agent directory regardless of scope, and configured scope
"shared" used a literal shared container name.

Measured before the fix, two guests on one shared agent:
  scope=agent(default) rw -> same scope key, same workspace
  scope=agent(default) ro -> same scope key, same workspace
  scope=session        rw -> distinct keys but SAME workspace
  scope=session        ro -> isolated

So only one of four combinations isolated guests, and it was not the default.
The authorization layer promised "edit only your own sessions" while the
container layer handed every guest the same writable workspace.

Role-required sessions now derive their sandbox identity from the session
creator: the scope key is principal-qualified, so different guests never
share a container or workspace while one guest's own sessions still do (per
guest, not per session). Configured "rw" resolves to "ro" with an
operator-visible warning, configured "shared" resolves to an effective agent
scope, and a required session with no creator provenance fails closed before
provisioning. Sessions without the requirement keep today's behavior.
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations docker Docker and sandbox tooling agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete
steipete marked this pull request as ready for review August 26, 2026 16:58
@steipete
steipete requested a review from a team as a code owner August 26, 2026 16:58
@steipete steipete closed this Aug 26, 2026
@steipete steipete reopened this Aug 26, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 26, 2026, 1:21 PM ET / 17:21 UTC.

ClawSweeper review

What this changes

The PR keys role-required sandbox containers and workspaces to the persisted authenticated creator, forces an effective agent scope, caps configured writable access to read-only, and updates diagnostics and docs.

Merge readiness

⛔ Blocked until real behavior proof is added - 8 items remain

Keep open: the principal-qualified scope fixes the shared-container identity, but it silently turns configured guest write access into read-only access and disables editing. Final-effect isolation proof is also still needed.

Likely related people: steipete (high-confidence feature owner).

Priority: P1
Reviewed head: a78d3516ddbd8ae43f595df027cb79a9c01c638b
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The isolation direction is useful, but the patch removes configured guest write capability and lacks required final-effect boundary proof.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Authority-chain proof required: the PR describes tests and layout derivation, but provides no after-fix real-backend trace showing guest B cannot read or write guest A's workspace; post redacted Docker or equivalent production-path evidence. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Authority-chain proof required: the PR describes tests and layout derivation, but provides no after-fix real-backend trace showing guest B cannot read or write guest A's workspace; post redacted Docker or equivalent production-path evidence. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current-main behavior: Current main resolves the configured sandbox unchanged after deciding a session is sandboxed, so configured rw access remains effective before this PR.
Changed access decision: The PR converts a role-required session with configured rw access to ro before provisioning.
User-visible consequence: The updated sandbox documentation states that ro disables write, edit, and apply_patch.
Findings 1 actionable finding [P1] Preserve writable guest workspaces
Security Needs attention Prove real backend isolation: Current coverage derives paths and uses a registered test backend, but does not show an actual backend refusing guest B access to guest A's workspace after the new principal-qualified scope reaches provisioning.

Live Verification

Command: pnpm openclaw sandbox explain --help

Result: PASS (completed)

$ node scripts/run-node.mjs sandbox explain --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 81.35 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.6s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 11.3s
[plugin-control-plane-loads] verified 36 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases completed in 3316ms (slowest: built plugin control-plane loads 2743ms)
│
◇

OpenClaw 2026.8.1 (a78d351) — All your chats, one OpenClaw.

Usage: openclaw sandbox explain [options]

Explain effective sandbox/tool policy for a session/agent

Options:
  --agent ‹id›     Agent id to inspect (defaults to derived agent)
  -h, --help       Display help for command
  --json           Output result as JSON (default: false)
  --session ‹key›  Session key to inspect (defaults to agent main)

Examples:
  openclaw sandbox explain
    Show effective sandbox config.
  openclaw sandbox explain --session agent:main:main
    Explain a specific session.
  openclaw sandbox explain --agent w
… output truncated …

Assertions:

  • PASS expect_output: Show effective sandbox config.

How this fits together

Gateway role policy stamps a sandbox requirement on a session created by an authenticated person. The agent sandbox layer reads that stored requirement to choose a runtime identity, workspace mounts, and tool access before provisioning a backend.

flowchart LR
A[Authenticated creator] --> B[Session creation]
B --> C[Stored sandbox requirement]
C --> D[Sandbox runtime resolver]
D --> E[Principal-scoped identity]
E --> F[Workspace and backend provisioning]
F --> G[Guest tool access]
Loading

Decision needed

Question Recommendation
Should role-required guest sessions retain configured write capability through a private per-creator workspace, rather than being unconditionally capped to read-only? Retain isolated writes: Use a creator-scoped writable workspace while preserving a read-only shared agent mount.

Why: The PR deliberately trades away an existing writable workflow to preserve isolation; choosing whether that loss is acceptable is a security and product-boundary decision.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Authority-chain proof required: the PR describes tests and layout derivation, but provides no after-fix real-backend trace showing guest B cannot read or write guest A's workspace; post redacted Docker or equivalent production-path evidence. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Preserve writable guest workspaces (P1) - This overwrites configured rw access with ro for every role-required session. The documented ro mode disables write, edit, and apply_patch, so guests lose their own editing workflow rather than receiving an isolated writable workspace. Keep the shared agent mount read-only but make the creator-scoped workspace writable, with a two-guest regression test.
  • Resolve security concern: Prove real backend isolation - Current coverage derives paths and uses a registered test backend, but does not show an actual backend refusing guest B access to guest A's workspace after the new principal-qualified scope reaches provisioning.
  • Resolve merge risk (P1) - Existing role-required sessions configured with workspaceAccess: rw lose write, edit, and apply_patch with no private writable replacement.
  • Resolve merge risk (P1) - The principal-derived scope reaches backend provisioning, but available evidence does not show a real backend rejecting the nearest forbidden guest before workspace I/O.
  • Improve patch quality - Make configured rw use a creator-scoped writable workspace while retaining a read-only agent mount.
  • Improve patch quality - Add final-effect proof for guest B being denied guest A's workspace before backend I/O, with an actual backend trace.

Findings

  • [P1] Preserve writable guest workspaces — src/agents/sandbox/context.ts:189-193
  • [medium] Prove real backend isolation — src/agents/sandbox/context.ts:189
Agent review details

Security

Needs attention: The patch changes a principal-to-workspace security boundary without final-effect proof that a second guest is rejected before I/O.

PR surface

Source +62, Tests +267, Docs +25. Total +354 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 5 75 13 +62
Tests 6 277 10 +267
Docs 2 25 0 +25
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 377 23 +354

Review metrics

Metric Value Why it matters
Production versus test delta production +62 net, tests +267 net, docs +25 The security repair adds runtime policy and substantial regression coverage, but the production path currently removes configured guest write capability.
Configured access change 1 changed behavior: required-session rw becomes ro Operators who selected writable sandbox access will see guest write tools disabled after merge.

Stored data model

Persistent data-model change detected: serialized state: src/commands/sandbox-explain.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Preserve private writable workspaces (recommended)
    Refactor the required-session mount model so configured rw writes only to the creator-scoped workspace and never to the shared agent workspace.
  2. Accept read-only guest sessions
    Land the cap only if maintainers explicitly intend role-required guests to lose all workspace mutation tools.

Technical review

Best possible solution:

Keep the shared agent workspace read-only while making the creator-scoped sandbox workspace writable when the operator configured rw, then prove guest A can write only its own workspace and guest B cannot access it.

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

Yes—source inspection gives a high-confidence path: a role-required session with configured workspaceAccess: rw is resolved to ro, which disables its write tools.

Is this the best way to solve the issue?

No. Principal-scoped identity solves the collision, but capping rw to ro removes the configured write workflow instead of providing a private writable workspace.

Full review comments:

  • [P1] Preserve writable guest workspaces — src/agents/sandbox/context.ts:189-193
    This overwrites configured rw access with ro for every role-required session. The documented ro mode disables write, edit, and apply_patch, so guests lose their own editing workflow rather than receiving an isolated writable workspace. Keep the shared agent mount read-only but make the creator-scoped workspace writable, with a two-guest regression test.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The PR changes the active role-required sandbox path and can disable guest editing for existing configured deployments.
  • add merge-risk: 🚨 compatibility: Configured workspaceAccess: rw changes to effective ro for every role-required session.
  • add merge-risk: 🚨 security-boundary: Principal-derived identity now controls container and workspace allocation without final-effect proof against a second guest.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Authority-chain proof required: the PR describes tests and layout derivation, but provides no after-fix real-backend trace showing guest B cannot read or write guest A's workspace; post redacted Docker or equivalent production-path evidence. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P1: The PR changes the active role-required sandbox path and can disable guest editing for existing configured deployments.
  • merge-risk: 🚨 compatibility: Configured workspaceAccess: rw changes to effective ro for every role-required session.
  • merge-risk: 🚨 security-boundary: Principal-derived identity now controls container and workspace allocation without final-effect proof against a second guest.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Authority-chain proof required: the PR describes tests and layout derivation, but provides no after-fix real-backend trace showing guest B cannot read or write guest A's workspace; post redacted Docker or equivalent production-path evidence. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [medium] Prove real backend isolation — src/agents/sandbox/context.ts:189
    Current coverage derives paths and uses a registered test backend, but does not show an actual backend refusing guest B access to guest A's workspace after the new principal-qualified scope reaches provisioning.
    Confidence: 0.88

What I checked:

Likely related people:

  • steipete: Authored the merged role-required sandbox feature and the current sandbox-isolation work. (role: feature owner and recent sandbox contributor; confidence: high; commits: 7f7448e96dbb, a78d3516ddbd; files: src/agents/sandbox/context.ts, src/agents/sandbox/runtime-status.ts, src/agents/sandbox/shared.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.

@steipete
steipete merged commit 52715a4 into main Aug 26, 2026
464 of 487 checks passed
@steipete
steipete deleted the steipete/role-sandbox-per-guest branch August 26, 2026 17:58
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
openclaw#130229)

* fix(sandbox): isolate role-required sandboxes per guest, not per agent

Role-forced sandboxing (openclaw#129926) contained a guest against the Gateway host
but not against other guests. Sandbox identity stayed agent-scoped, so every
session on a shared agent converged on one scope key, container and
workspace; configured workspaceAccess "rw" additionally pinned the workspace
to the shared agent directory regardless of scope, and configured scope
"shared" used a literal shared container name.

Measured before the fix, two guests on one shared agent:
  scope=agent(default) rw -> same scope key, same workspace
  scope=agent(default) ro -> same scope key, same workspace
  scope=session        rw -> distinct keys but SAME workspace
  scope=session        ro -> isolated

So only one of four combinations isolated guests, and it was not the default.
The authorization layer promised "edit only your own sessions" while the
container layer handed every guest the same writable workspace.

Role-required sessions now derive their sandbox identity from the session
creator: the scope key is principal-qualified, so different guests never
share a container or workspace while one guest's own sessions still do (per
guest, not per session). Configured "rw" resolves to "ro" with an
operator-visible warning, configured "shared" resolves to an effective agent
scope, and a required session with no creator provenance fails closed before
provisioning. Sessions without the requirement keep today's behavior.

* chore: drop accidentally committed sandbox scope repro scratch file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant