Skip to content

default.rules is not honored for sandbox-escaping commands even when execpolicy returns allow #15298

Open

Description

@arteagacz

What version of the Codex App are you using (From “About Codex” dialog)?

26.313.41514

What subscription do you have?

Pro

What platform is your computer?

Microsoft Windows NT 10.0.26200.0 x64 (Windows 11 Pro)

What issue are you seeing?

default.rules is not being treated as sufficient authorization for commands that need sandbox escape.

I reproduced this in both the Codex desktop app and the Codex CLI on Windows with:

  • trusted project
  • windows.sandbox = "elevated"
  • default.rules containing an allow rule for the command

Example rules tested:

prefix_rule(pattern=["git", "add"], decision="allow")
prefix_rule(pattern=["C:\\Program Files\\PowerShell\\7\\pwsh.exe", "-Command", "git", "add"], decision="allow")

Then I verified both forms with codex execpolicy check in PowerShell:

codex execpolicy check --pretty --rules $HOME\.codex\rules\default.rules -- git add -A

Result:

{
  "matchedRules": [
    {
      "prefixRuleMatch": {
        "matchedPrefix": ["git", "add"],
        "decision": "allow"
      }
    }
  ],
  "decision": "allow"
}

And also:

codex execpolicy check --pretty --rules $HOME\.codex\rules\default.rules -- "C:\Program Files\PowerShell\7\pwsh.exe" -Command git add -A

Result:

{
  "matchedRules": [
    {
      "prefixRuleMatch": {
        "matchedPrefix": [
          "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
          "-Command",
          "git",
          "add"
        ],
        "decision": "allow"
      }
    }
  ],
  "decision": "allow"
}

Despite that, asking Codex to run git add -A still produces a manual approval prompt when the command needs to escape the sandbox to write under .git.

Inside the sandbox, the failure is expected:

fatal: Unable to create '.../.git/index.lock': Permission denied

What seems wrong is that a command already allowed by default.rules still requires manual confirmation instead of being treated as authorized.

What steps can reproduce the bug?

  1. On Windows, set windows.sandbox = "elevated".
  2. Mark the repo as trusted.
  3. Add an allow rule to ~/.codex/rules/default.rules for git add, for example:
prefix_rule(pattern=["git", "add"], decision="allow")
  1. Restart Codex.
  2. Confirm the rule matches:
codex execpolicy check --pretty --rules $HOME\.codex\rules\default.rules -- git add -A
  1. Ask Codex in the desktop app or CLI to run:
git add -A
  1. Observe that Codex still prompts for manual approval when the command needs sandbox escape to write under .git, even though execpolicy check already says the command is allowed.

I also tested the wrapped PowerShell form and got the same result:

prefix_rule(pattern=["C:\Program Files\PowerShell\7\pwsh.exe", "-Command", "git", "add"], decision="allow")

codex execpolicy check returns allow for that form too, but the actual command still prompts.

What is the expected behavior?

If default.rules allows a command, and codex execpolicy check returns allow for that same command, Codex should be able to run it without a second manual approval prompt.

At minimum, default.rules should be sufficient authorization for the required sandbox escape for that allowed command.

If that is not the intended model, the docs should say clearly that default.rules only affects execpolicy matching and does not suppress sandbox-approval prompts for those same commands.

Additional information

Important detail: this is not just a desktop-app issue. I reproduced the same behavior in Codex CLI.

So the problem seems broader than one UI surface.

I also tested multiple rule shapes to rule out argv-shape confusion:

  • plain command form: pattern=["git", "add"]
  • wrapped PowerShell form: pattern=["C:\Program Files\PowerShell\7\pwsh.exe", "-Command", "git", "add"]

Both shapes return allow from codex execpolicy check.

Another important detail: if I approve the prompt using "Yes, and don't ask again...", Codex auto-saves this exact rule into default.rules:

prefix_rule(pattern=["C:\Program Files\PowerShell\7\pwsh.exe", "-Command", "git add -A"], decision="allow")

That exact auto-saved rule works.

So the surprising behavior is more specific than "rules never work": user-authored general prefix rules that codex execpolicy check says are allowed still do not suppress the approval prompt, but the exact command rule auto-saved by the prompt does suppress it.

This makes it look like the real execution path is honoring a narrower, different rule shape than the one accepted by codex execpolicy check and documented in default.rules.

Activity

  1. added
    app
    on Mar 20, 2026
  2. added
    bug
    CLI
    windows-os
    sandbox
    on Mar 20, 2026
  3. github-actions commented on Mar 20, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  4. arteagacz commented on Mar 20, 2026

    @arteagacz
    Author

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    * [Desktop shell tool still prompts for sandbox approval even when default.rules allows the command #15292](https://github.com/openai/codex/issues/15292)
    

    Powered by Codex Action

    That was the original issue i submitted, but it needed further testing and clarification, so i closed it and opened this one with additional important details. The issues listed as potential duplicates in #15292 are not duplicates.

  5. ignatremizov commented on Mar 20, 2026

    @ignatremizov
    Image

    FYI you can edit issues text instead of closing and opening new ones

  6. arteagacz commented on Mar 20, 2026

    @arteagacz
    Author
    Image

    FYI you can edit issues text instead of closing and opening new ones

    Yes, normally, but the reopen button was showing an insufficient permissions hint for some reason.

  7. removed
    CLI
    app
    on Mar 20, 2026
  8. bobscorporation commented on Mar 23, 2026

    @bobscorporation

    +1 on this, rules being broken makes codex impossible to use for even medium length tasks as i have to stay and babysit.

  9. Bibendus83 commented on Apr 21, 2026

    @Bibendus83

    I have no idea if my codex setup is broken or what but I have to constantly approve ANY git command and there is no way to properly add generic allowance rules that will prevent that.

    It's possible the issue has something to do with this #15214

  10. codemeow commented on May 7, 2026

    @codemeow

    Same problem. Linux, VScode with codex. It keeps asking with any level of access or sandbox.

  11. ashmcmn commented on Sep 24, 2026

    @ashmcmn

    Adding a related macOS reproduction: Codex Desktop showed an ‘Allow once’ prompt for a read-only gcloud builds list invocation (project, limit, sort, and format flags), despite ~/.codex/rules/default.rules allowing the exact gcloud builds list prefix. The command shown in the prompt starts with that prefix, and the rule has been present for months. I ran codex execpolicy check against the exact invocation using ~/.codex/rules/default.rules; it returned decision: allow and matched the gcloud builds list prefix. I did not execute the gcloud command itself. This points to the desktop approval/execution path rather than a prefix-matching problem.

  12. EdwardMillen commented on Oct 18, 2026

    @EdwardMillen

    I've found a workaround for this on Windows at least (or rather, ChatGPT and Codex did it for me). This is what ChatGPT suggested I should post here explaining it:


    I've reproduced a related problem with Codex on native Windows, and found a workaround that may help narrow down the cause.

    Environment:

    • Codex VS Code extension: 26.1007.21434
    • Bundled CLI: 0.162.0-alpha.17.2
    • Windows PowerShell 5.1
    • Approval rule: prefix_rule(pattern=["git", "add"], decision="allow")

    The interesting finding is that equivalent PowerShell command spellings produce different approval behaviour, even though they pass identical arguments to the native executable.

    Command Result
    git add --dry-run README.md Automatically allowed
    git add --dry-run -- README.md Requires escalation/approval
    git add --dry-run '--' README.md Automatically allowed
    git commit --dry-run -m 'Approval dry-run' Automatically allowed
    Commit dry-run with --author="Name <email>" Requires escalation/approval
    Commit dry-run with '--author=Name <email>' Automatically allowed

    All commands used the same exec_command backend and were executed through powershell.exe -Command.

    A separate argument-printing test confirmed that the quoted and unquoted variants pass identical arguments to native programs.

    PowerShell's parser represents bare -- as a CommandParameterAst, whereas '--' is a StringConstantExpressionAst. This suggests the difference arises during command analysis before execution, rather than in Git itself.

    I haven't established which internal Codex parser branch is responsible, so this is an observation rather than a confirmed root cause.

    Practical workaround: Quoting -- as '--', and quoting the entire --author=... argument, allows my existing Git prefix rules to work without additional approval prompts.

    Although demonstrated using Git, the underlying issue may apply to other external commands whose PowerShell syntax prevents Codex from recognising the executable and arguments correctly.

    This may also be relevant to #15294, which describes the broader PowerShell command-wrapping problem.


    And here's what I've currently added to AGENTS.md, which hopefully covers it, although I haven't actually tested it with a separate agent/conversation:

    ### Windows Git command approvals
    
    To avoid unnecessary Codex approval prompts on Windows:
    
    - Run Git staging and commit commands separately, using `exec_command` with the repository as `workdir`. Don't add an explicit PowerShell wrapper.
    - Quote the `--` separator: `git add '--' <files>`.
    - Quote the entire author argument: `git commit '--author=Codex (<model>, <reasoning effort>) <codex@localhost>' -m 'Message'`.
    
    These forms were tested with the existing Git approval rules. Equivalent unquoted forms can trigger unnecessary approval prompts due to PowerShell command parsing. Don't broaden approval permissions to work around this.
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsandboxwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions