fix(agents): map sandbox workdir container paths to host#31841
fix(agents): map sandbox workdir container paths to host#31841steipete merged 2 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryFixes sandbox exec workdir validation for container-native paths by mapping container paths (like Key changes:
Implementation notes:
Confidence Score: 5/5
Last reviewed commit: 4454036 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4454036dab
ℹ️ 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".
| if (!workdir.startsWith(`${containerRoot}/`)) { | ||
| return undefined; |
There was a problem hiding this comment.
Skip remapping for host paths already inside workspace
The prefix check here treats any workdir beginning with containerWorkdir as a container path, so host paths can be remapped incorrectly when the host workspace itself is under that prefix (for example workspaceDir=/workspace/project and workdir=/workspace/project/src). In that case rel becomes project/src, and the resolved host directory becomes /workspace/project/project/src, which can either fall back unexpectedly or run commands from the wrong directory; before this change, the original host path would resolve correctly.
Useful? React with 👍 / 👎.
4454036 to
b95c3a9
Compare
|
Landed via temp rebase onto main.
Thanks @liuxiaopai-ai! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b95c3a958d
ℹ️ 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".
| if (!workdir.startsWith(`${containerRoot}/`)) { | ||
| return undefined; | ||
| } | ||
| const rel = workdir | ||
| .slice(containerRoot.length + 1) |
There was a problem hiding this comment.
Skip remapping when workdir is already a host path
mapContainerWorkdirToHost currently treats any workdir that starts with containerWorkdir + "/" as a container path, so valid host paths can be rewritten incorrectly when the host workspace itself is under that prefix (for example workspaceDir=/workspace/openclaw, containerWorkdir=/workspace, workdir=/workspace/openclaw/src becomes /workspace/openclaw/openclaw/src). Fresh evidence: I reproduced this by calling resolveSandboxWorkdir with those values, and it fell back with a warning even though /workspace/openclaw/src exists, which means sandbox exec can run from the wrong directory or silently degrade to the fallback path.
Useful? React with 👍 / 👎.
Summary
execvalidatesworkdiron the host path tree, so container-native paths like/workspacefail validation and fall back.workdir.resolveSandboxWorkdirnow maps container workdir prefixes (default/workspace, plus customcontainerWorkdir) back to host workspace paths before sandbox-path validation.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
execwith sandbox-enabled container workdirs now correctly accepts container path inputs (for example/workspaceand nested paths) by mapping them to the mounted host workspace before validation.Security Impact (required)
No)No)No)No)No)Yes, explain risk + mitigation:Repro + Verification
Environment
src/agentscontainerWorkdir=/workspaceSteps
workdir: "/workspace"and a temp host workspace root./workspace/..../sandbox-root/...).Expected
Actual
Evidence
Human Verification (required)
What you personally verified (not just CI), and how:
/workspace, nested/workspace/scripts/runner, and custom container root mapping.Compatibility / Migration
Yes)No)No)Failure Recovery (if this breaks)
src/agents/bash-tools.shared.ts.Risks and Mitigations
containerRoot/-prefixed paths and still passes throughassertSandboxPathroot constraints.