#13873: fix(sandbox): prevent Windows PATH from poisoning docker exec
agents
stale
Cluster:
Sandbox Path Management Fixes
## Summary
- On Windows hosts, `buildDockerExecArgs` passes the host `PATH` env var (e.g. `C:\Windows\System32;C:\Users\...`) to `docker exec -e PATH=...`. Docker uses this PATH to resolve the executable argument (`sh`), which fails because Windows paths don't exist inside the Linux container — producing:
```
OCI runtime exec failed: exec: "sh": executable file not found in $PATH: unknown
```
- Skip `PATH` in the `-e` env loop — it's already handled separately via `OPENCLAW_PREPEND_PATH` + shell-level export, so passing it raw via `-e` was redundant and harmful on Windows
- Use absolute `/bin/sh` instead of bare `sh` to eliminate PATH dependency during Docker's exec lookup entirely
## Reproduction
1. Run openclaw on a Windows host with Docker Desktop (WSL2 backend)
2. Configure a sandbox with `mode: "all"` and any Docker image
3. Trigger any exec tool call — every call fails with exit code 127
## Test plan
- [x] Verified `docker exec -e "PATH=C:\Windows" container sh -c "echo test"` reproduces the exact error
- [x] Verified `docker exec container /bin/sh -c "echo test"` works on Debian bookworm-slim containers
- [x] `/bin/sh` is POSIX-required and exists on all Linux container images (Debian, Alpine, Ubuntu, etc.)
- [ ] CI tests pass
- [ ] Verify no regression on macOS/Linux hosts (PATH is already handled via OPENCLAW_PREPEND_PATH)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR hardens Docker sandbox exec on Windows hosts by avoiding leakage of the host `PATH` into `docker exec -e` (which can break Docker’s executable lookup when the PATH contains Windows-style entries). It also switches docker exec to invoke the shell via an absolute path (`/bin/sh`) both in `buildDockerExecArgs` (used by the exec tool) and in sandbox container setup (`createSandboxContainer`), removing dependency on PATH resolution inside Docker’s exec implementation.
These changes live in the sandbox execution plumbing (`src/agents/bash-tools.shared.ts` and `src/agents/sandbox/docker.ts`) and should improve cross-platform reliability when running Linux containers from Windows.
<h3>Confidence Score: 4/5</h3>
- Mostly safe to merge once the failing test expectation is updated.
- The functional change is narrowly scoped (PATH handling + absolute shell path) and aligns with the reported Windows/Docker failure mode. The only definite merge-blocker found is a now-stale unit test that still asserts `sh` instead of `/bin/sh`, which should fail CI until updated.
- src/agents/bash-tools.test.ts (update the assertion in the buildDockerExecArgs test)
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#3907: fix(sandbox): use absolute /bin/sh path + add allowedReadPaths config
by pvoo · 2026-01-29
82.6%
#8161: fix(sandbox): block dangerous environment variables from Docker con...
by yubrew · 2026-02-03
82.5%
#16509: Fix sandbox path validation rejecting Docker bind mount paths
by Clawborn · 2026-02-14
81.7%
#11878: fix: add missing error handler to execDocker child process
by Yida-Dev · 2026-02-08
80.5%
#11820: fix(sandbox): remap container paths in sandboxed file tools
by steflsd · 2026-02-08
80.2%
#14308: fix(sandbox): pass docker.env config to container creation
by wboudy · 2026-02-11
80.1%
#7826: feat(sandbox): add Docker Sandboxes (microVM) as alternative backend
by HODL-Community · 2026-02-03
78.6%
#9657: fix(doctor): warn when sandbox mode enabled without Docker
by mcaxtr · 2026-02-05
78.5%
#8186: fix(sandbox): validate setupCommand to prevent shell injection
by yubrew · 2026-02-03
78.5%
#13666: test: make docker-setup Bash path portable on Windows
by rmdmattingly · 2026-02-10
78.4%