Allow writable gitdir for current worktree in sandboxed workspace-write mode
What variant of Codex are you using?
CLI (Linux, bubblewrap sandbox)
What feature would you like to see?
Add a way to make the current worktree gitdir writable while remaining in sandboxed workspace-write mode.
Today, when running under the Linux bubblewrap sandbox, .git and resolved gitdir: targets are force-mounted read-only after writable roots are applied. That means git fetch fails because Git cannot update .git/FETCH_HEAD (and related metadata), even when the worktree itself is writable.
An opt-in mechanism is needed for the current worktree, for example a config setting or CLI flag that relaxes the protected .git/gitdir carveout for that worktree only.
This is not solvable with --add-dir today, because the read-only mount for .git/gitdir is applied after the write dirs from the command line, so the read-only mount wins.
Additional information
- This appears to have changed for the bubblewrap path in commit
dcc4d7b634e0c732e5dab9ab04b6f3b67bfa55f1on March 8, 2026 (linux-sandbox: honor split filesystem policies in bwrap (#13453)). - Before that change,
git fetchin sandboxed workspace-write mode used to work in my setup. - Concrete failure:
error: cannot open .git/FETCH_HEAD: Read-only file system. - Request: keep the default safety behavior, but add an explicit override for trusted local workflows that need Git metadata writes without switching all the way to
danger-full-accessor using per-command escalation.
7 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
seems same with #12280
Thanks for the report! This just brings the linux sandbox behavior in line with macOS where writes to .git are not allowed. This was a missing feature on Landlock which is why it was working before.
Before https://github.com/openai/codex/pull/13453, the bubblewrap path was accidentally not re-applying the default .git / resolved gitdir read-only carveout after writable roots, so git metadata writes worked in workspace-write on Linux by accident. https://github.com/openai/codex/pull/13453 fixed bwrap to consume the split filesystem policy directly and re-apply those read-only subpaths.
Additional repro from Codex Desktop (macOS) in workspace-write mode:
/Users/.../Development/Hero-Soccerand/Users/.../Development)..git/from agent tool calls fails (Operation not permitted/ unable to create.git/index.lock)..gitfrom external terminal and Codex terminal, so this appears specific to sandboxed tool execution.Question from field use: does config support a wildcard allow-list for many repos (e.g.
/Users/.../Development/*.git), or is explicit per-repo opt-in required once an override exists?I opened a push-specific variant of this writable-gitdir problem: #21869 .
In
workspace-writewithnetwork_access=true, I reproduced a case wheregit pushupdated the remote branch first, then failed updating the local remote-tracking ref under.git/refs/remotes/origin/*because the sandbox made the gitdir read-only. The command printed the lockfile error but exited0.The resulting state is worse than ordinary
.git/index.lockfailures:HEADorigin/<branch>remains stalegit statusstill says[ahead 1]git fetchcannot repair because.git/FETCH_HEADis also read-onlySo the fix here is not only “Git cannot write
.git”; it is also that Codex should not let/interpret a remote side effect as a failed local-only Git operation. At minimum, after this push-specific failure, Codex should verify withgit ls-remoteand report “remote push succeeded; local tracking ref is stale” rather than debugging auth/permissions/branch state or retrying blindly.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.
Additional impact from Codex Desktop on macOS using a Codex-managed linked worktree:
workspace-write.git addandgit commitrequire writes to the external worktree gitdir/common directory, so the agent requests sandbox escalation and unattended work stops waiting for approval.The available configuration workaround creates an undesirable security tradeoff: adding the shared
/path/to/main-repo/.gitdirectory towritable_rootspermits much more than staging and creating an ordinary commit. It also removes the filesystem boundary for refs, repository config, worktree metadata, and other Git state.The desired capability is narrower than "make
.gitwritable":.gitdirectory as a generic writable root.This matters for long-running autonomous tasks: repeated sandbox approval prompts for ordinary local staging/commit operations halt otherwise safe, scoped execution. A Git-aware mediated capability, or an operation-scoped permission for the current worktree, would preserve both autonomy and the intended safety boundary.
All paths above are placeholders; the behavior is not repository-specific.