Fix unsandboxed terminal sandbox wrapping for quoted shell execution#307487
Merged
dileepyavan merged 2 commits intomicrosoft:mainfrom Apr 2, 2026
Merged
Fix unsandboxed terminal sandbox wrapping for quoted shell execution#307487dileepyavan merged 2 commits intomicrosoft:mainfrom
dileepyavan merged 2 commits intomicrosoft:mainfrom
Conversation
Yoyokrazy
approved these changes
Apr 2, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the unsandboxed terminal sandbox wrapping path to avoid syntactic breakage when commands contain tricky shell characters (notably trailing backslashes), by executing the full command via the active shell using -c rather than interpolating raw text into a parenthesized wrapper.
Changes:
- Plumb the active shell through the command-line sandbox rewriter into
TerminalSandboxService.wrapCommand. - Extend
ITerminalSandboxService.wrapCommand/TerminalSandboxService.wrapCommandto accept an optionalshellfor unsandboxed wrapping. - Switch unsandboxed wrapping to
env TMPDIR="..." <shell> -c '<command>'(with a parenthesized fallback when no shell is provided), and add/adjust regression tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/terminalSandboxService.test.ts | Updates/extends regression tests to validate the new unsandboxed wrapping format and blocked-domain unsandboxed behavior. |
| src/vs/workbench/contrib/terminalContrib/chatAgentTools/common/terminalSandboxService.ts | Adds an optional shell parameter and implements the new unsandboxed wrapping strategy using env … <shell> -c …. |
| src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/commandLineRewriter/commandLineSandboxRewriter.ts | Forwards the active shell into wrapCommand so unsandboxed wrapping can use the correct shell. |
...workbench/contrib/terminalContrib/chatAgentTools/test/browser/terminalSandboxService.test.ts
Show resolved
Hide resolved
src/vs/workbench/contrib/terminalContrib/chatAgentTools/common/terminalSandboxService.ts
Show resolved
Hide resolved
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.
Fixes #306463, #304861
Summary
This updates the unsandboxed terminal sandbox wrapping path to execute the full input command through the active shell using
-c, instead of interpolating raw command text directly into a parenthesized wrapper.This addresses the case where a command ends with a trailing backslash and breaks the wrapper syntax by escaping the closing delimiter.
Changes
wrapCommandcall.TerminalSandboxService.wrapCommandto accept the shell for unsandboxed wrapping.env TMPDIR="..." <shell> -c '<command>'TMPDIRWhy
The previous unsandboxed wrapper embedded raw command text directly in a subshell-like wrapper. When the input command ended with a trailing backslash, that backslash could escape the wrapper's closing syntax and produce an invalid command.
By passing the command as a quoted
-cpayload, the command body is treated as data by the outer shell parser, which avoids the trailing-backslash failure while still scopingTMPDIRto that invocation.Testing
./scripts/test.sh --run src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/terminalSandboxService.test.tsnode --experimental-strip-types build/hygiene.ts src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/commandLineRewriter/commandLineSandboxRewriter.ts src/vs/workbench/contrib/terminalContrib/chatAgentTools/common/terminalSandboxService.ts src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/terminalSandboxService.test.ts