Skip to content

fix(sandbox): remap container paths in sandboxed file tools - #11820

Closed
steflsd wants to merge 2 commits into
openclaw:mainfrom
lsdcapital:fix/sandbox-container-path-remap
Closed

steflsd wants to merge 2 commits into
openclaw:mainfrom
lsdcapital:fix/sandbox-container-path-remap

Conversation

@steflsd

@steflsd steflsd commented Feb 8, 2026 •

Copy link
Copy Markdown

Problem

When a sandbox runs with workspaceAccess: "none", the host sandbox directory (e.g. /data/clawfront-data/{sandbox-id}/) is bind-mounted into the Docker container at /workspace. Both paths point to the same physical files.

The agent executes commands inside Docker via exec, so it discovers files at container paths like /workspace/projects/foo/package.json. When it then tries to use the structured read/write/edit tools with those paths, the gateway-side assertSandboxPath rejects them — because /workspace/... on the host is not inside the sandbox root.

This forces the agent to fall back to cat/echo > via bash inside Docker, which works but bypasses the structured file tools entirely — losing MIME detection, image sanitization, path normalization, and the sandbox symlink guard.

Fix

Add a remapContainerPath step in wrapSandboxPathGuard that translates container paths back to host paths before validation. For example, /workspace/foo.txt becomes /data/clawfront-data/{sandbox-id}/foo.txt. Paths that don't match the container workdir prefix pass through unchanged.

Test plan

  • New tests: container-absolute read/write/edit paths resolve to sandbox dir
  • New test: paths outside the container workspace prefix are still rejected
  • Existing sandbox + workspace path tests pass
  • Full test suite passes (pnpm build && pnpm check && pnpm test)

🤖 AI-assisted (Claude Code) · fully tested · I understand what the code does

🤖 Generated with Claude Code

Greptile Overview

Greptile Summary

This change threads sandbox.containerWorkdir into the sandboxed read/write/edit tool wrappers and adds a remapContainerPath step inside wrapSandboxPathGuard so container-absolute paths (e.g. /workspace/foo.txt) are rewritten to the host sandbox root before running assertSandboxPath. The accompanying tests extend pi-tools.workspace-paths.test.ts to cover container-absolute read/write/edit paths and confirm that non-workdir-prefixed container paths remain blocked.

Confidence Score: 4/5

  • This PR is generally safe to merge once a path-traversal edge case in container path remapping is addressed.
  • The change is localized and backed by new tests, but remapContainerPath can join .. segments from a container path into a host path, which will cause unexpected rejections (and could become risky if surrounding validation changes).
  • src/agents/pi-tools.read.ts

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Feb 8, 2026

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +267 to +269
if (filePath.startsWith(prefix)) {
return path.join(hostRoot, filePath.slice(prefix.length));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Container path remap escape
remapContainerPath can map a container path like /workspace/../outside.txt to path.join(hostRoot, "../outside.txt"), which resolves outside hostRoot and will then be rejected by assertSandboxPath (breaking the intended “container paths work” behavior). This can happen if the exec tool returns non-normalized paths. Consider normalizing/validating after remap (e.g., ensure the remapped path stays within hostRoot and/or reject any .. segments in the container-relative suffix) before mutating record.path.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-tools.read.ts
Line: 267:269

Comment:
**Container path remap escape**
`remapContainerPath` can map a container path like `/workspace/../outside.txt` to `path.join(hostRoot, "../outside.txt")`, which resolves outside `hostRoot` and will then be rejected by `assertSandboxPath` (breaking the intended “container paths work” behavior). This can happen if the exec tool returns non-normalized paths. Consider normalizing/validating after remap (e.g., ensure the remapped path stays within `hostRoot` and/or reject any `..` segments in the container-relative suffix) before mutating `record.path`.


How can I resolve this? If you propose a fix, please make it concise.

With workspaceAccess: "none", the sandbox host dir is mounted into Docker
at /workspace. When the agent uses exec inside Docker, it sees container
paths like /workspace/file.txt, but passing these to the gateway's
read/write/edit tools fails because assertSandboxPath rejects them —
/workspace/... on the host is not within the sandbox root.

Remap container paths (e.g. /workspace/foo) to host paths (e.g.
/data/sandbox-id/foo) in wrapSandboxPathGuard before validation.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@steflsd
steflsd force-pushed the fix/sandbox-container-path-remap branch from 0403666 to f24c16c Compare February 9, 2026 17:52
Ensures remapContainerPath rejects paths with .. segments that would
resolve outside hostRoot after remap. Also remaps container paths in
exec tool media output.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added stale Marked as stale due to inactivity and removed stale Marked as stale due to inactivity labels Feb 21, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Mar 9, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #pr-thunderdome-dangerzone on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

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

Labels

agents Agent runtime and tooling stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant