Skip to content

fix: execute sandboxed file ops inside containers - #4026

Merged
steipete merged 3 commits into
openclaw:mainfrom
davidbors-snyk:fix/execute-sandboxed-file-operations-inside-containers
Feb 13, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
davidbors-snyk:fix/execute-sandboxed-file-operations-inside-containers

Conversation

@davidbors-snyk

@davidbors-snyk davidbors-snyk commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

I discussed this issue with @steipete before opening the PR. This is a bigger patch. It moves sandboxed file operations from the host inside the container. This is meant as a solution to security issues that could arise from symlink race-condition attacks when file ops are performed on the host. A completely secure host-side implementation is impossible as Node.js doesn't expose openat().

Greptile Overview

Greptile Summary

This PR introduces a SandboxFsBridge that routes sandboxed file operations through docker exec inside the sandbox container rather than performing them on the host. Call sites for apply_patch, read/write/edit, and image loading were updated to use the bridge when sandboxed, and loadWebMedia was extended to support a custom readFile override.

Overall this aligns with the repo’s sandbox architecture by making file reads/writes occur in the same isolated environment as other sandboxed execution, reducing host-side TOCTOU/symlink race exposure.

Main things to double-check are API surface consistency (execDocker vs execDockerRaw cancellation), and error handling granularity in the new bridge (especially where errors are currently collapsed to “not found”).

Confidence Score: 4/5

  • This PR is likely safe to merge, with a couple of error-handling and API-consistency concerns worth addressing.
  • The changes are cohesive and mostly mechanical rewires to route file I/O through a new sandbox bridge; the main risk areas are (1) cancellation propagation for docker calls due to the narrowed execDocker signature, and (2) stat() masking non-ENOENT errors as null, which can hide operational failures. No obvious security regressions were found in the new shell scripts (arguments are passed positionally and quoted).
  • src/agents/sandbox/docker.ts, src/agents/sandbox/fs-bridge.ts

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

Context used:

  • Context from dashboard - CLAUDE.md (source)
  • Context from dashboard - AGENTS.md (source)

@openclaw-barnacle openclaw-barnacle Bot added channel: whatsapp-web Channel integration: whatsapp-web agents Agent runtime and tooling labels Jan 29, 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.

3 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment thread src/agents/sandbox/docker.ts Resolved
@greptile-apps

greptile-apps Bot commented Feb 3, 2026

Copy link
Copy Markdown
Contributor
Additional Comments (2)

src/agents/sandbox/fs-bridge.ts
[P1] stat() treats any non-zero stat exit as “not found”, which can mask real errors.

runCommand(..., { allowFailure: true }) then if (result.code !== 0) return null; (src/agents/sandbox/fs-bridge.ts:161-167). This collapses permission errors, missing stat binary, invalid paths, etc. into ENOENT behavior, which can lead to confusing fallbacks (e.g., image path rewrite) and harder debugging.

It would be safer to only return null for the “no such file” case and throw (or propagate stderr) for other failures.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/sandbox/fs-bridge.ts
Line: 161:167

Comment:
[P1] `stat()` treats *any* non-zero `stat` exit as “not found”, which can mask real errors.

`runCommand(..., { allowFailure: true })` then `if (result.code !== 0) return null;` (src/agents/sandbox/fs-bridge.ts:161-167). This collapses permission errors, missing `stat` binary, invalid paths, etc. into ENOENT behavior, which can lead to confusing fallbacks (e.g., image path rewrite) and harder debugging.

It would be safer to only return `null` for the “no such file” case and throw (or propagate stderr) for other failures.

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

src/web/media.ts
[P2] New loadWebMedia() overload defaults optimizeImages to true, which changes behavior for callers passing options objects.

Previously, all callers effectively got optimizeImages: true. Now object callers get optimizeImages: options.optimizeImages ?? true (src/web/media.ts:221-234), but number/undefined callers also force optimizeImages: true. This is correct, but it’s easy to miss that object callers can now disable optimization (and bypass the previous implicit behavior).

If this is intentional, consider adding/adjusting a unit test to lock in the overload semantics (number vs. options object) so future refactors don’t regress it.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/web/media.ts
Line: 221:229

Comment:
[P2] New `loadWebMedia()` overload defaults `optimizeImages` to `true`, which changes behavior for callers passing options objects.

Previously, all callers effectively got `optimizeImages: true`. Now object callers get `optimizeImages: options.optimizeImages ?? true` (src/web/media.ts:221-234), but number/undefined callers also force `optimizeImages: true`. This is correct, but it’s easy to miss that object callers can now disable optimization (and bypass the previous implicit behavior).

If this is intentional, consider adding/adjusting a unit test to lock in the overload semantics (number vs. options object) so future refactors don’t regress it.

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

@davidbors-snyk
davidbors-snyk force-pushed the fix/execute-sandboxed-file-operations-inside-containers branch from fae8175 to bdaaa6d Compare February 3, 2026 14:18
@seheepeak

seheepeak commented Feb 13, 2026 •

Copy link
Copy Markdown
Contributor

+1, this is the right direction.

I've been dealing with the host-path vs container-path mismatch a lot while working with sandbox agents. The core problem is simple — exec runs inside the container, but file tools run on the host. Agents find files at /workspace/... via exec, then read/write rejects those paths. The path remapping PRs (#11820, #14810, #9730) keep trying to translate between the two path spaces, but that's inherently fragile (traversal edge cases, prefix matching bugs, hardcoded workdir assumptions — each PR gets flagged for a different variant of the same issue).

My current workaround is mounting the container workspace at the exact same absolute path as the host (e.g. /home/user/workspace/project:/home/user/workspace/project) so both contexts see the same paths. It works, but it's ugly — you end up with unnecessarily long container paths that are just host path artifacts, and again it's just a workaround.

This PR just sidesteps all of that by running file I/O inside the container too. One execution context, no translation needed. The SandboxFsBridge abstraction is clean and the Greptile concerns from the initial review look addressed in the current diff.

There are still some related path issues around bundled skills, system prompt <location> tags, and other places where host paths leak into the sandbox context (#6346, #7915, etc). But I think getting alignment on this core approach first makes those follow-ups much more straightforward to tackle.

This would fix or largely address #9560, #9348, #2432. Would love to see this move forward.

@steipete
steipete force-pushed the fix/execute-sandboxed-file-operations-inside-containers branch from 24ce93f to 795ec6a Compare February 13, 2026 15:28
@steipete
steipete merged commit 29d7839 into openclaw:main Feb 13, 2026
9 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

Thanks @davidbors-snyk!

skyhawk14 pushed a commit to skyhawk14/openclaw that referenced this pull request Feb 13, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 795ec6a
Co-authored-by: davidbors-snyk <[email protected]>
Co-authored-by: steipete <[email protected]>
Reviewed-by: @steipete
GwonHyeok pushed a commit to learners-superpumped/openclaw that referenced this pull request Feb 15, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 795ec6a
Co-authored-by: davidbors-snyk <[email protected]>
Co-authored-by: steipete <[email protected]>
Reviewed-by: @steipete
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 795ec6a
Co-authored-by: davidbors-snyk <[email protected]>
Co-authored-by: steipete <[email protected]>
Reviewed-by: @steipete
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 795ec6a
Co-authored-by: davidbors-snyk <[email protected]>
Co-authored-by: steipete <[email protected]>
Reviewed-by: @steipete
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 795ec6a
Co-authored-by: davidbors-snyk <[email protected]>
Co-authored-by: steipete <[email protected]>
Reviewed-by: @steipete
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 795ec6a
Co-authored-by: davidbors-snyk <[email protected]>
Co-authored-by: steipete <[email protected]>
Reviewed-by: @steipete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: whatsapp-web Channel integration: whatsapp-web size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants