Fixing rgpath for terminal sandboxing#301948
Merged
dileepyavan merged 24 commits intomainfrom Mar 16, 2026
Merged
Conversation
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR targets terminal sandboxing reliability by adjusting how the sandbox helper exposes the bundled rg (ripgrep) dependency, addressing failures where sandboxed terminal tools never run due to missing ripgrep.
Changes:
- Inject
ILogServiceintoSandboxHelperServiceand log the computed ripgrep path. - Stop overriding
SandboxManager.initialize’s ripgrep config from_rgPath, and instead try to makergdiscoverable by extendingPATHin the wrapped command’s environment prefix. - Add helper logic to append the ripgrep binary directory to
PATH.
Comments suppressed due to low confidence (3)
src/vs/platform/sandbox/node/sandboxHelperService.ts:81
SandboxManager.initialize(...)runs before the wrapped command is produced, so updatingPATHonly in_getSandboxEnvironmentPrefix()won’t affect the sandbox runtime’s dependency check that currently fails with “Required: ripgrep (rg)”. Also,normalizedRuntimeConfig.ripgrepis now only provided when the caller suppliesruntimeConfig.ripgrep, butTerminalSandboxServicenever sets it, so initialize will fall back to searching forrgon the current process PATH and likely keep failing. Consider always providing a ripgrep config here (e.g. using VS Code’s bundled ripgrep path) or otherwise ensuringrgis discoverable in the environment used duringinitialize.
This issue also appears in the following locations of the same file:
- line 30
- line 104
ripgrep: runtimeConfig.ripgrep ? {
command: runtimeConfig.ripgrep.command,
args: runtimeConfig.ripgrep?.args ? [...runtimeConfig.ripgrep.args] : undefined,
} : undefined,
mandatoryDenySearchDepth: runtimeConfig.mandatoryDenySearchDepth,
allowPty: runtimeConfig.allowPty,
};
await SandboxManager.initialize(normalizedRuntimeConfig, request => this._requestSandboxPermission(request));
return SandboxManager.wrapWithSandbox(`${this._getSandboxEnvironmentPrefix()} ${command}`);
src/vs/platform/sandbox/node/sandboxHelperService.ts:35
- The ripgrep path is currently derived from
appRoot/node_modules/@vscode/ripgrep/bin/rg. In built distributions the module/binary is commonly stored undernode_modules.asarand the executable undernode_modules.asar.unpacked(see other ripgrep usages that rewritergPathto the unpacked location). If_rgPathpoints at a non-existent location, both the new PATH injection and any ripgrep command resolution will be ineffective. Suggest resolving the ripgrep binary using@vscode/ripgrep’srgPath(and rewriting to the unpacked path when needed) instead of constructing it manually fromappRoot.
this._rgPath = nativeEnvironmentService.appRoot
? this._pathJoin(nativeEnvironmentService.appRoot, 'node_modules', '@vscode', 'ripgrep', 'bin', 'rg')
: undefined;
this._tempDir = nativeEnvironmentService.tmpDir?.path;
logService.info('SandboxHelperService#constructor ripgrep path', this._rgPath ?? 'undefined');
}
src/vs/platform/sandbox/node/sandboxHelperService.ts:108
_getPathWithRipgrepDirappends the ripgrep directory to the end of PATH. If anotherrgexists earlier on PATH, the sandbox runtime will pick that one, which can reintroduce “missing/incorrect dependency” issues and makes behavior less deterministic. Consider prepending the ripgrep directory so the bundledrgtakes precedence.
const rgDir = dirname(this._rgPath);
const currentPath = process.env['PATH'];
const path = process.platform === 'win32' ? win32 : posix;
return currentPath ? `${currentPath}${path.delimiter}${rgDir}` : rgDir;
}
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
DonJayamanne
approved these changes
Mar 16, 2026
dileepyavan
added a commit
that referenced
this pull request
Mar 16, 2026
This reverts commit 00d6a08.
dileepyavan
added a commit
that referenced
this pull request
Mar 16, 2026
This reverts commit 00d6a08.
dileepyavan
added a commit
that referenced
this pull request
Mar 17, 2026
* Revert "Fixing rgpath for terminal sandboxing (#301948)" This reverts commit 00d6a08. * Revert "[Terminal_Sandboxing] Enable default trusted domains and updates to sandbox config (#301852)" This reverts commit af55754. * Revert "[Terminal_sandbox] Notify when user consent is needed for permissions in sandbox. (#301413)" This reverts commit 0cb8d31.
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(#301928)