FIX: resolve real tool binary to prevent sandbox PATH shadowing#16
Open
Stuart B. Wilkins (stuwilkins) wants to merge 1 commit into
Open
FIX: resolve real tool binary to prevent sandbox PATH shadowing#16Stuart B. Wilkins (stuwilkins) wants to merge 1 commit into
Stuart B. Wilkins (stuwilkins) wants to merge 1 commit into
Conversation
Add resolve_real_tool_binary() to lib/bwrap_sandbox_lib.sh. On managed hosts the dotfiles wrapper (~/.local/bin/opencode) shadows the real npm binary on PATH. command -v opencode then resolves to the wrapper; its directory gets added to SANDBOX_PATH and bind-mounted into the --clearenv sandbox, where AZURE_*/N2SNSCRIPTS_LIB are stripped and the wrapper fails with 'cannot locate gpg-passwd.sh' (the double-invocation bug). Fix: detect dotfiles wrappers by checking whether readlink -f resolves to a path containing /config/scripts/. If so, substitute the npm-prefix binary directly. Hard-error if the npm binary is also absent (returning the wrapper would silently recreate the bug). Non-npm tools (system packages) are unaffected — the candidate is returned unchanged. Wire resolve_real_tool_binary into all four wrappers: bwopencode, bwclaude, bwcodex, bwcopilot. Assisted-by: opencode:claude-opus-4-8 Assisted-by: opencode:claude-sonnet-4-6 Assisted-by: opencode:gpt-5.6-sol
Stuart B. Wilkins (stuwilkins)
requested review from
Copilot and
Thomas A Caswell (tacaswell)
July 18, 2026 14:01
Copilot started reviewing on behalf of
Stuart B. Wilkins (stuwilkins)
July 18, 2026 14:02
View session
There was a problem hiding this comment.
Pull request overview
This PR hardens the bubblewrap sandbox wrappers against PATH shadowing by dotfiles “wrapper” scripts (e.g., ~/.local/bin/opencode) on managed hosts, ensuring the sandbox mounts and executes the real tool binary rather than a wrapper that depends on stripped environment variables.
Changes:
- Add
resolve_real_tool_binary()tolib/bwrap_sandbox_lib.shto detect dotfiles wrappers (viareadlink -fcontaining/config/scripts/) and substitute the npm-prefix binary. - Wire the new resolver into
bwopencode,bwclaude,bwcodex, andbwcopilotso tool discovery no longer depends on wrapper paths.
Reviewed changes
Copilot reviewed 1 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| lib/bwrap_sandbox_lib.sh | Adds resolve_real_tool_binary() to bypass dotfiles wrapper symlinks and return the real npm-installed binary (or error if absent). |
| bin/bwopencode | Uses resolve_real_tool_binary opencode for host tool resolution before sandboxing. |
| bin/bwcopilot | Uses resolve_real_tool_binary copilot for host tool resolution before sandboxing. |
| bin/bwcodex | Uses resolve_real_tool_binary codex for host tool resolution before sandboxing. |
| bin/bwclaude | Uses resolve_real_tool_binary claude for host tool resolution before sandboxing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Detect dotfiles wrapper: the symlink target contains /config/scripts/ | ||
| # (the dotfiles convention for per-tool wrapper scripts). | ||
| real_candidate="$(readlink -f "${candidate}" 2> /dev/null || printf '%s' "${candidate}")" | ||
| if [[ "${real_candidate}" == */config/scripts/* ]]; then |
Contributor
There was a problem hiding this comment.
What is the source of this convention?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add resolve_real_tool_binary() to lib/bwrap_sandbox_lib.sh. On managed
hosts the dotfiles wrapper (~/.local/bin/opencode) shadows the real npm
binary on PATH. command -v opencode then resolves to the wrapper; its
directory gets added to SANDBOX_PATH and bind-mounted into the --clearenv
sandbox, where AZURE_*/N2SNSCRIPTS_LIB are stripped and the wrapper fails
with 'cannot locate gpg-passwd.sh' (the double-invocation bug).
Fix: detect dotfiles wrappers by checking whether readlink -f resolves to
a path containing /config/scripts/. If so, substitute the npm-prefix
binary directly. Hard-error if the npm binary is also absent (returning
the wrapper would silently recreate the bug). Non-npm tools (system
packages) are unaffected — the candidate is returned unchanged.
Wire resolve_real_tool_binary into all four wrappers: bwopencode,
bwclaude, bwcodex, bwcopilot.
Assisted-by: opencode:claude-opus-4-8
Assisted-by: opencode:claude-sonnet-4-6
Assisted-by: opencode:gpt-5.6-sol