Skip to content

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

Open

Description

@yobiscus

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 (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.

Activity

  1. added
    enhancement
    on Mar 11, 2026
  2. added
    bug
    CLI
    sandbox
    on Mar 11, 2026
  3. github-actions commented on Mar 11, 2026

    @github-actions
    Contributor

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

    Powered by Codex Action

  4. removed
    bug
    CLI
    on Mar 11, 2026
  5. ryush00 commented on Mar 19, 2026

    @ryush00

    seems same with #12280

  6. viyatb-oai commented on Mar 26, 2026

    @viyatb-oai
    Contributor

    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 #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. #13453 fixed bwrap to consume the split filesystem policy directly and re-apply those read-only subpaths.

  7. jaredplumb commented on Mar 29, 2026

    @jaredplumb

    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?

  8. alvbd commented on May 9, 2026

    @alvbd

    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.

  9. K1-R1 commented on May 23, 2026

    @K1-R1

    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/[email protected]

    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.

  10. chemitaro commented on Jul 11, 2026

    @chemitaro

    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.

  11. solomatov commented on Nov 17, 2026

    @solomatov

    I think, this description is too much about how it's to be done, than the real problem it's supposed to solve. For me, the main issue is being able to let agent create commits, and do some git operations while preserving sandbox boundary.

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

    enhancementsandbox

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions