Avoid PowerShell profiles in elevated Windows sandbox#21400
Merged
Conversation
8a99efa to
768e928
Compare
dylan-hurd-oai
approved these changes
May 13, 2026
768e928 to
cefb7db
Compare
cefb7db to
81416be
Compare
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Why
On Windows, elevated sandboxed commands run under a dedicated sandbox account while
HOME/USERPROFILEcan still point at the real user's profile directory. For PowerShell login shells, that combination can make the sandbox account try to load the real user's PowerShell profile script. If the sandbox account's execution policy differs from the real user's policy, startup can emit profile-loading errors before the requested command runs.For this backend, loading the profile is not a faithful user login shell: it is cross-account profile execution. Treating these PowerShell invocations as non-login shells avoids that invalid startup path.
Why This Happens Late
The normal
logindecision is resolved when shell argv is created, but that point is too early to make this Windows sandbox-specific decision. At argv creation time we do not yet know the actual sandbox attempt that will run the command. A turn can include sandboxed and unsandboxed attempts, and a broad turn-level override would also affect Full Access commands where the user's profile should remain available.Instead, this change carries the selected
ShellTypealongside the argv and applies the-NoProfileadjustment in the shell runtimes once theSandboxAttemptis known. That keeps the override scoped to actualWindowsRestrictedTokenattempts withWindowsSandboxLevel::Elevated.The runtime uses the selected shell metadata rather than re-detecting PowerShell from argv. That avoids brittle parsing and covers PowerShell invocation shapes such as
-EncodedCommand.What Changed
exec_command/ unified exec requests and shell tool requests.-NoProfilefor PowerShell commands only when the runtime is about to execute a sandboxed elevated Windows attempt.-EncodedCommand, existing-NoProfile, legacy restricted-token attempts, unsandboxed attempts, and non-PowerShell commands.Verification
cargo test -p codex-core disable_powershell_profile_testscargo test -p codex-core test_get_commandcargo clippy --fix --tests --allow-dirty --allow-no-vcs -p codex-coreA full
cargo test -p codex-corerun was also attempted during development, but it still hit an unrelated stack overflow inagent::controltests before reaching this area.