codex - 💡(How to fix) Fix Linux sandbox mounts linked worktree gitdir read-only after writable ancestor bind [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#19786Fetched 2026-04-28 06:37:16
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×3commented ×1unlabeled ×1

Root Cause

The problem is not specific to one repo name. It happens because the linked worktree .git file points outside the active worktree to a sibling common repo:

Code Example

gitdir: /home/user/projects/repo/.git/worktrees/repo-1

---

[permissions.example.filesystem]
"/home/user/projects" = "write"

---

gitdir=/home/user/projects/repo/.git/worktrees/repo-1
common=/home/user/projects/repo/.git

TARGET                                          SOURCE                                                     OPTIONS
/home/user/projects/repo/.git/worktrees/repo-1  /dev/...[/home/user/projects/repo/.git/worktrees/repo-1]  ro,nosuid,nodev,relatime

GITDIR_NOT_WRITABLE

---

fatal: Unable to create '/home/user/projects/repo/.git/worktrees/repo-1/index.lock': Read-only file system

---

set -euo pipefail

rm -rf /tmp/codex-worktree-repro
mkdir -p /tmp/codex-worktree-repro/projects
cd /tmp/codex-worktree-repro/projects

git init repo
cd repo
git config user.email "[email protected]"
git config user.name "Test User"
printf 'initial\n' > file.txt
git add file.txt
git commit -m initial

git worktree add ../repo-1 -b repo-1
cd ../repo-1

cat .git
git rev-parse --path-format=absolute --git-dir
git rev-parse --path-format=absolute --git-common-dir

printf 'change\n' > new.txt

---

[permissions.example.filesystem]
"/tmp/codex-worktree-repro/projects" = "write"

---

codex sandbox linux -- bash -lc '
  pwd
  cat .git
  gitdir=$(git rev-parse --path-format=absolute --git-dir)
  common=$(git rev-parse --path-format=absolute --git-common-dir)
  printf "gitdir=%s\ncommon=%s\n" "$gitdir" "$common"
  findmnt -T "$gitdir" -o TARGET,SOURCE,OPTIONS
  findmnt -T "$common" -o TARGET,SOURCE,OPTIONS
  test -w "$gitdir" && echo GITDIR_WRITABLE || echo GITDIR_NOT_WRITABLE
  git add new.txt
'

---

GITDIR_NOT_WRITABLE
fatal: Unable to create '/tmp/codex-worktree-repro/projects/repo/.git/worktrees/repo-1/index.lock': Read-only file system

---

git rev-parse --path-format=absolute --git-dir

---

GITDIR_WRITABLE

---

git add new.txt

---

/home/user/projects/repo
/home/user/projects/repo-1
/home/user/projects/repo-2

---

gitdir: /home/user/projects/repo/.git/worktrees/repo-1
RAW_BUFFERClick to expand / collapse

What version of Codex CLI is running?

codex-cli 0.125.0

What subscription do you have?

Pro

Which model were you using?

gpt-5.5

What platform is your computer?

Linux 6.8.0-110-generic x86_64 x86_64

What terminal emulator and version are you using (if applicable)?

Mate terminal

What issue are you seeing?

On Linux, Codex CLI's workspace-write sandbox makes linked Git worktree metadata read-only when the worktree's .git file points to a sibling repo's common Git directory.

PII-redacted setup:

  • Current workspace: /home/user/projects/repo-1
  • .git is a file containing:
gitdir: /home/user/projects/repo/.git/worktrees/repo-1
  • The Codex filesystem profile makes the projects directory writable:
[permissions.example.filesystem]
"/home/user/projects" = "write"

Inside codex sandbox linux, the common repo becomes visible and writable, but the active worktree-specific gitdir is mounted read-only.

Observed inside the sandbox:

gitdir=/home/user/projects/repo/.git/worktrees/repo-1
common=/home/user/projects/repo/.git

TARGET                                          SOURCE                                                     OPTIONS
/home/user/projects/repo/.git/worktrees/repo-1  /dev/...[/home/user/projects/repo/.git/worktrees/repo-1]  ro,nosuid,nodev,relatime

GITDIR_NOT_WRITABLE

The effective mount policy appears to make the broad projects directory writable, then make the active linked-worktree gitdir read-only. The later, more specific read-only mount wins for that path.

This breaks git add. Confirmed failure:

fatal: Unable to create '/home/user/projects/repo/.git/worktrees/repo-1/index.lock': Read-only file system

Codex CLI version tested: codex-cli 0.125.0

Platform: Linux x86_64

Install method: npm global package

Sandbox mode: workspace-write

What steps can reproduce the bug?

Minimal reproduction, using only temporary paths:

set -euo pipefail

rm -rf /tmp/codex-worktree-repro
mkdir -p /tmp/codex-worktree-repro/projects
cd /tmp/codex-worktree-repro/projects

git init repo
cd repo
git config user.email "[email protected]"
git config user.name "Test User"
printf 'initial\n' > file.txt
git add file.txt
git commit -m initial

git worktree add ../repo-1 -b repo-1
cd ../repo-1

cat .git
git rev-parse --path-format=absolute --git-dir
git rev-parse --path-format=absolute --git-common-dir

printf 'change\n' > new.txt

Then configure Codex so the projects directory is writable. Example shape:

[permissions.example.filesystem]
"/tmp/codex-worktree-repro/projects" = "write"

Run this from /tmp/codex-worktree-repro/projects/repo-1:

codex sandbox linux -- bash -lc '
  pwd
  cat .git
  gitdir=$(git rev-parse --path-format=absolute --git-dir)
  common=$(git rev-parse --path-format=absolute --git-common-dir)
  printf "gitdir=%s\ncommon=%s\n" "$gitdir" "$common"
  findmnt -T "$gitdir" -o TARGET,SOURCE,OPTIONS
  findmnt -T "$common" -o TARGET,SOURCE,OPTIONS
  test -w "$gitdir" && echo GITDIR_WRITABLE || echo GITDIR_NOT_WRITABLE
  git add new.txt
'

Actual result:

GITDIR_NOT_WRITABLE
fatal: Unable to create '/tmp/codex-worktree-repro/projects/repo/.git/worktrees/repo-1/index.lock': Read-only file system

What is the expected behavior?

When the active workspace is writable and is a linked Git worktree, Codex should ensure the active worktree-specific gitdir is writable.

Specifically, this path should be writable inside the sandbox:

git rev-parse --path-format=absolute --git-dir

Expected result inside codex sandbox linux:

GITDIR_WRITABLE

Expected Git behavior:

git add new.txt

should succeed instead of failing to create index.lock.

Implementation-wise, either of these would satisfy the expectation:

  1. Do not make the active worktree gitdir read-only when it is already under a writable root.
  2. Add a later/more-specific writable rule for git rev-parse --path-format=absolute --git-dir.

Deny rules for secret-like files such as .env should still take precedence.

Additional information

This affects generic linked worktree layouts such as:

/home/user/projects/repo
/home/user/projects/repo-1
/home/user/projects/repo-2

The problem is not specific to one repo name. It happens because the linked worktree .git file points outside the active worktree to a sibling common repo:

gitdir: /home/user/projects/repo/.git/worktrees/repo-1

Making /home/user/projects visible/writable solves common-dir visibility and allows git status, but it does not allow Git write operations because the active worktree gitdir remains read-only.

This appears to be a Linux workspace-write sandbox policy bug for linked Git worktrees.

extent analysis

TL;DR

The issue can be resolved by adding a more specific writable rule for the active worktree gitdir in the Codex filesystem profile.

Guidance

  • Identify the active worktree gitdir path using git rev-parse --path-format=absolute --git-dir and add a writable rule for this path in the Codex filesystem profile.
  • Verify that the active worktree gitdir is writable by running test -w "$gitdir" && echo GITDIR_WRITABLE || echo GITDIR_NOT_WRITABLE inside the sandbox.
  • Ensure that the writable rule for the active worktree gitdir takes precedence over any deny rules for secret-like files.
  • Test the fix by running git add new.txt inside the sandbox and verifying that it succeeds.

Example

[permissions.example.filesystem]
"/home/user/projects" = "write"
"/home/user/projects/repo/.git/worktrees/repo-1" = "write"

Notes

This fix assumes that the active worktree gitdir path can be determined dynamically using git rev-parse --path-format=absolute --git-dir. If this is not possible, a more static approach may be required.

Recommendation

Apply a workaround by adding a more specific writable rule for the active worktree gitdir in the Codex filesystem profile, as this is a Linux workspace-write sandbox policy bug for linked Git worktrees.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Linux sandbox mounts linked worktree gitdir read-only after writable ancestor bind [1 comments, 2 participants]