Windows elevated sandbox requires repeated approval for git worktree operations because .git is denied
Summary
In codex-cli 0.123.0 on Windows, git worktree operations now require repeated manual approval when running with workspace-write and windows.sandbox = "elevated".
The workspace itself is trusted and writable, but writes under .git are denied by the Windows sandbox. As a result, normal Git workflows such as creating an issue worktree, committing, merging, or cleaning up worktrees frequently leave the sandbox and require approval.
Environment
- Codex CLI:
codex-cli 0.123.0 - OS: Windows 10 Pro, WindowsVersion 2009
- Sandbox mode:
workspace-write - Windows sandbox backend:
elevated - GitHub CLI used for this report:
gh 2.91.0 - Project is trusted in Codex config
- The repository/worktree path is inside configured writable roots
What changed
This appears to be caused by the elevated Windows sandbox now inheriting the legacy deny-write paths for protected directories such as .git.
Relevant upstream change:
- #17365:
Include legacy deny paths in elevated Windows sandbox setup
Before this change, versions such as rust-v0.112.0 through rust-v0.114.0 appear to contain the earlier .git protection logic, but not the elevated-backend merge introduced by #17365. In practice, the elevated backend did not prompt for these .git writes as frequently in that older setup.
Steps to reproduce
- On Windows, configure Codex with:
sandbox_mode = "workspace-write"
[windows]
sandbox = "elevated"
- Trust a project whose repository path is inside a writable root.
- Start Codex in that repository.
- Ask Codex to create an issue worktree, for example:
git worktree add .worktrees/S1-04 -b S1-04 sprint01
- Observe that the operation requires approval because Git needs to write under
.git. - Continue normal issue-branch workflow, such as commit, merge, prune, or remove worktree.
- Observe repeated approvals for normal Git metadata writes.
Expected behavior
Trusted workspaces should allow common Git metadata operations needed for normal development workflows without repeated approval, especially when the operation is initiated inside the trusted repository and the target worktree is under the repository, for example .worktrees/<issue-id>.
At minimum, there should be a documented and configurable way to allow common Git metadata writes for trusted repositories while keeping the default protection for untrusted workspaces.
Actual behavior
Even though the repository path is trusted and inside writable roots, the sandbox treats .git as protected/denied. Commands that update repository metadata need to leave the sandbox and prompt for approval repeatedly.
This makes worktree-based workflows noisy and difficult to automate. A typical issue workflow may require approval for:
git worktree addgit add/git commitgit mergegit worktree removegit worktree prune
Why this matters
Worktree-based development is a common way to isolate issue branches, sprint branches, and parallel agent work. Requiring approval every time Git updates .git makes the workflow much less usable in trusted local projects.
I understand why .git is protected by default: it prevents unintended repository metadata writes. The problem is that there is currently no practical escape hatch for trusted repositories where Git operations are an intentional part of the workflow.
Possible fixes
Some possible approaches:
- Add a config option to allow Git metadata writes for trusted repositories, for example
allow_git_metadata_writes = trueunder the workspace sandbox config. - Allow a narrower set of Git operations under
.gitwhen the command isgitand the working directory is inside a trusted workspace. - Treat
.git/worktrees, refs, index locks, and other Git-managed metadata differently from arbitrary writes under.git. - Document the recommended configuration for worktree-heavy workflows if the current behavior is intentional.
Related issues / PRs
- #7071: CLI sandbox cannot commit because
.gitis read-only - #15505:
.gitis mounted read-only even though Codex is configured for workspace-write - #17036: allow limited git writes in workspace sandbox
- #17365: Include legacy deny paths in elevated Windows sandbox setup
3 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Thanks for the duplicate check.
#18918 is closely related, but I think this issue adds a narrower workflow-specific case:
git worktreebased development in a trusted Windows workspace.The main problem is not only
git commit/.git/index.lock. A normal isolated issue-branch workflow now repeatedly needs approval for Git metadata operations such as:git worktree add .worktrees/<issue-id> -b <issue-id> <sprint-branch>git commitgit mergegit worktree removegit worktree pruneThis happens even when:
sandbox_mode = "workspace-write"[windows] sandbox = "elevated"I understand the security reason for protecting
.gitby default. The request here is for a safer escape hatch thandanger-full-access, for example a documented config option that allows Git metadata writes only for trusted repositories / trusted workspaces.danger-full-accessworks around the problem, but it is much broader than needed for this workflow. What I need is not unrestricted filesystem access, but the ability for Codex to perform intentional Git metadata operations in a trusted local repository.So if this should be tracked under #18918 or #17036, I am happy to close this and continue there. Otherwise, I think this issue is useful as the
git worktreeworkflow-specific case.I ran into the same safety/autonomy tradeoff: I wanted to keep Codex in a safer
workspace-writeposture, but normal local Git operations need writes under.git, so the options become either repeated approvals/manual Git or relaxing the sandbox much more than I wanted.I built a small local MCP server as a workaround:
codex-safe-git.Repo: https://github.com/K1-R1/codex-safe-git
It does not make
.gitbroadly writable and it does not expose arbitrary shell/Git access. Instead it gives Codex a narrow, auditable Git tool surface for things like status, diff summaries, branch preparation, and exact-file commits. Remote operations are intentionally out of scope.Install:
This is not a replacement for a proper upstream fix/config option, but it may be useful for people who want Codex to stay sandboxed while still letting it handle local Git workflows more autonomously.