Repository navigation
Conversation
| if (filePath.startsWith(prefix)) { | ||
| return path.join(hostRoot, filePath.slice(prefix.length)); | ||
| } |
There was a problem hiding this 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.
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]>
0403666 to
f24c16c
Compare
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]>
bfc1ccb to
f92900f
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
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 structuredread/write/edittools with those paths, the gateway-sideassertSandboxPathrejects 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
remapContainerPathstep inwrapSandboxPathGuardthat translates container paths back to host paths before validation. For example,/workspace/foo.txtbecomes/data/clawfront-data/{sandbox-id}/foo.txt. Paths that don't match the container workdir prefix pass through unchanged.Test plan
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.containerWorkdirinto the sandboxedread/write/edittool wrappers and adds aremapContainerPathstep insidewrapSandboxPathGuardso container-absolute paths (e.g./workspace/foo.txt) are rewritten to the host sandbox root before runningassertSandboxPath. The accompanying tests extendpi-tools.workspace-paths.test.tsto cover container-absolute read/write/edit paths and confirm that non-workdir-prefixed container paths remain blocked.Confidence Score: 4/5
remapContainerPathcan join..segments from a container path into a host path, which will cause unexpected rejections (and could become risky if surrounding validation changes).