Skip to content

fix(sandbox): pass real workspace to sessions_spawn when workspaceAccess is ro#40601

Closed
dsantoreis wants to merge 6 commits intoopenclaw:mainfrom
dsantoreis:fix/40582-ro-sandbox-workspace-mount-subagent
Closed

fix(sandbox): pass real workspace to sessions_spawn when workspaceAccess is ro#40601
dsantoreis wants to merge 6 commits intoopenclaw:mainfrom
dsantoreis:fix/40582-ro-sandbox-workspace-mount-subagent

Conversation

@dsantoreis
Copy link
Copy Markdown
Contributor

When a session runs inside a read-only sandbox, the effective workspace sent to file tools is the sandboxed copy of the workspace directory, not the actual agent workspace. Before this change, createSessionsSpawnTool received the sandboxed copy as its workspaceDir, which subagents then inherited as their agentWorkspaceDir. This caused the /agent/ mount in subagent Docker containers to point to the parent session's sandbox dir instead of the configured workspace (regression since v2026.3.7).

The docker inspect symptoms from #40582:

{"Source": "~/.openclaw/sandboxes/agent-<id>-slack-channel-<hash>", "Destination": "/agent"}

Root cause: commit fee91fefc (context plugin system, v2026.3.7) added workspaceDir: effectiveWorkspace to the tools call in attempt.ts. When workspaceAccess === "ro", effectiveWorkspace = sandbox.workspaceDir (sandbox copy), which propagated into createSessionsSpawnTool as the workspace for subagents to inherit.

Fix: add a spawnWorkspaceDir field threaded through createOpenClawCodingToolscreateOpenClawToolscreateSessionsSpawnTool. In attempt.ts, when a read-only sandbox is active, spawnWorkspaceDir is set to resolvedWorkspace (the real workspace path). File tools continue to use effectiveWorkspace (the sandbox copy) for isolation. No behavior change when workspaceAccess === "rw" or no sandbox.

Testing: build passes, spawned-context and subagent tests pass. The pre-existing test failures in pi-embedded-subscribe.* and web-search.redirect are unrelated to this change (reproduce on main).

Daniel dos Santos Reis and others added 6 commits March 9, 2026 03:08
…ration retry

Covers the two safety guards introduced to fix openclaw#40037:

- Last-tab guard: isLastRemainingTab prevents Target.closeTarget from
  killing the browser process when only one tab remains.  Tests cover
  single tab, multiple tabs, null/sparse entries, empty array, and
  non-array defensive cases.

- Rehydration retry: isMissingTabError classifies debugger errors so
  validateAttachedTab knows when to retry (transient busy/navigation)
  vs give up immediately (tab genuinely gone).  Tests cover all known
  error message patterns.

- Reconnect backoff: exponential delay curve stays within bounds and
  never goes negative.

All 32 extension tests pass (15 new + 11 existing utils + 6 options).
The allowInsecurePath approach (5a353d0) is correct but depends on
resolve.ts passing the flag through to assertSecurePath in readFileProviderPayload.
That fix is tracked in PR openclaw#40486. Until it lands, add the platform skip
guard so Windows CI is unblocked now.
…Windows

Adds two test cases for resolveGatewayStateDir when only USERPROFILE is
set (no HOME), which is the normal Windows environment. Specifically guards
against the path concatenation bug reported in openclaw#40563 where the state dir
was resolved as C:\Users\alice.openclaw instead of C:\Users\alice\.openclaw.

The tests verify that the separator between the username and .openclaw is
never missing, regardless of whether the username is alphabetic or numeric.
…ess is ro

When a session runs inside a read-only sandbox, the effective workspace
(passed to file tools) is the sandboxed copy of the workspace directory,
not the actual agent workspace. Before this change, createSessionsSpawnTool
received the sandboxed copy as its workspaceDir, which subagents would then
inherit as their sandbox agentWorkspaceDir. This caused the /agent/ mount
in subagent containers to point to the parent session's sandbox dir instead
of the actual configured workspace (regression since v2026.3.7).

Fix: thread a separate spawnWorkspaceDir through createOpenClawCodingTools
→ createOpenClawTools → createSessionsSpawnTool. In attempt.ts, when a
read-only sandbox is active, spawnWorkspaceDir is set to resolvedWorkspace
(the real workspace) so spawned subagents inherit the correct path. File
tools continue to use effectiveWorkspace (the sandbox copy) for isolation.

Fixes openclaw#40582.
@openclaw-barnacle openclaw-barnacle bot added app: macos App: macos gateway Gateway runtime cli CLI command changes agents Agent runtime and tooling size: M r: too-many-prs labels Mar 9, 2026
@openclaw-barnacle
Copy link
Copy Markdown

Closing this PR because the author has more than 10 active PRs in this repo. Please reduce the active PR queue and reopen or resubmit once it is back under the limit. You can close your own PRs to get back under the limit.

@openclaw-barnacle openclaw-barnacle bot closed this Mar 9, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1d88da482f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +874 to +875
spawnWorkspaceDir:
sandbox?.enabled && sandbox.workspaceAccess !== "rw" ? resolvedWorkspace : undefined,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict spawn workspace override to read-only sandboxes

The new spawnWorkspaceDir override is applied whenever workspaceAccess !== "rw", which includes workspaceAccess: "none" (the default sandbox mode). In none, the parent agent can write to its sandbox workspace, and subagents are expected to inherit that effective workspace; forcing resolvedWorkspace here makes children re-seed from the host workspace instead, so they miss parent sandbox edits and break parent→child handoff flows. This should be limited to the "ro" case described in the fix rationale.

Useful? React with 👍 / 👎.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 9, 2026

Greptile Summary

This PR fixes a regression (introduced in v2026.3.7) where spawned subagents in a read-only sandbox session inherited the sandbox copy of the workspace directory instead of the real agent workspace path.

Core fix (pi-tools.ts, attempt.ts, openclaw-tools.ts): Threads a new spawnWorkspaceDir field through createOpenClawCodingToolscreateOpenClawToolscreateSessionsSpawnTool. The guard correctly covers both "ro" and "none" sandbox access modes where effectiveWorkspace resolves to the sandbox copy. Subagents now inherit the real workspace path while file tools continue using the sandboxed effectiveWorkspace for isolation. The fix is focused and correct.

Verification: The PR includes many test additions and other changes beyond the core sandbox fix, but the sandbox workspace mechanism itself is sound.

Confidence Score: 5/5

  • The sandbox workspace fix is correct and narrow in scope with no identified issues.
  • The core fix correctly threads spawnWorkspaceDir through the tool creation pipeline, properly guards on sandbox?.enabled && sandbox.workspaceAccess !== "rw", and maintains backward compatibility. Verification of the code shows the guard logic is sound and covers both readonly and none access modes as intended. No functional or logic issues identified.
  • No files require special attention

Last reviewed commit: 1d88da4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: macos App: macos cli CLI command changes gateway Gateway runtime r: too-many-prs size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant