Allow writable gitdir for current worktree in sandboxed workspace-write mode

Open 💬 7 comments Opened Mar 11, 2026 by yobiscus
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

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 dcc4d7b634e0c732e5dab9ab04b6f3b67bfa55f1 on March 8, 2026 (linux-sandbox: honor split filesystem policies in bwrap (#13453)).
  • Before that change, git fetch in 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-access or using per-command escalation.

View original on GitHub ↗

7 Comments

github-actions[bot] contributor · 4 months ago

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

  • #14068

Powered by Codex Action

ryush00 · 4 months ago

seems same with #12280

viyatb-oai contributor · 3 months ago

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.

jaredplumb · 3 months ago

Additional repro from Codex Desktop (macOS) in workspace-write mode:

  • Writable roots include both project root and parent (e.g. /Users/.../Development/Hero-Soccer and /Users/.../Development).
  • Normal file writes in repo succeed.
  • Any write under .git/ from agent tool calls fails (Operation not permitted / unable to create .git/index.lock).
  • Same machine/user can write to .git from 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?

alvbd · 2 months ago

I opened a push-specific variant of this writable-gitdir problem: #21869 .

In workspace-write with network_access=true, I reproduced a case where git push updated 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 exited 0.

The resulting state is worse than ordinary .git/index.lock failures:

  • remote branch equals local HEAD
  • local origin/<branch> remains stale
  • git status still says [ahead 1]
  • git fetch cannot repair because .git/FETCH_HEAD is also read-only

So 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 with git ls-remote and report “remote push succeeded; local tracking ref is stale” rather than debugging auth/permissions/branch state or retrying blindly.

K1-R1 · 1 month ago

I ran into the same safety/autonomy tradeoff: I wanted to keep Codex in a safer workspace-write posture, 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 .git broadly 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:

go install github.com/K1-R1/codex-safe-git/cmd/codex-safe-git-mcp@v0.4.3

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.

chemitaro · 9 days ago

Additional impact from Codex Desktop on macOS using a Codex-managed linked worktree:

  • The active worktree itself is inside a configured writable root.
  • The worktree's resolved gitdir and common Git directory are stored elsewhere, for example:
/path/to/codex-worktrees/<id>/repo
/path/to/main-repo/.git/worktrees/<worktree-id>
/path/to/main-repo/.git
  • Normal source edits succeed in workspace-write.
  • git add and git commit require 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/.git directory to writable_roots permits 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 .git writable":

  1. Allow staging explicitly selected files in the current managed worktree.
  2. Allow creating a normal commit after inspecting the staged diff and running hooks.
  3. Keep destructive/history-rewriting operations such as reset, rebase, forced ref updates, and hook bypass outside that capability.
  4. Resolve the active worktree gitdir/common directory automatically, without requiring users to expose the entire shared .git directory 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.