Repository navigation
Description
Summary
In a Codex thread on a bb-managed worktree, git branch -D fails inside the sandbox because git cannot create <commonDir>/packed-refs.lock. git stash pop hits the same lock and exits 0, but leaves refs/stash pointing at the popped commit. I expected both to work, since creating a branch and pushing a stash already do.
Versions and environment
- bb 0.43.4, desktop app, macOS
- Provider: codex, Codex CLI 0.157.1, default workspace permissions
- Environment: bb worktree (
--new-environment worktree)
Steps to reproduce
In a Codex thread spawned with --new-environment worktree, run inside the sandbox without escalation:
git branch bb-sandbox-test && git branch -D bb-sandbox-testecho probe > probe.txt && git add probe.txt && git stash push -- probe.txt && git stash popgit stash list; git for-each-ref refs/stash
Expected vs actual
Actual:
$ git branch bb-sandbox-test && git branch -D bb-sandbox-test
error: could not delete reference refs/heads/bb-sandbox-test: Unable to create '<repo>/.git/packed-refs.lock': Operation not permitted
(exit 1)
$ git stash push -- probe.txt && git stash pop
Saved working directory and index state WIP on <branch>: 3068402 ...
...
error: Unable to create '<repo>/.git/packed-refs.lock': Operation not permitted
Dropped refs/stash@{0} (184822bc04fcacfccc47b84c8f4b46d016f654dd)
(exit 0)
$ git stash list; git for-each-ref refs/stash
184822bc04fcacfccc47b84c8f4b46d016f654dd commit refs/stash
Expected: the branch is deleted, and after stash pop no refs/stash remains.
Evidence
gitWritableRootsForWorkspace grants the worktree's own git dir, <commonDir>/objects, and the ref directory for HEAD (refs/heads and logs/refs/heads). It never grants the common dir itself, and git takes <commonDir>/packed-refs.lock to delete any ref.
Granting <commonDir>/packed-refs, packed-refs.lock, refs/ and logs/refs/ would cover branch and stash deletion while keeping <commonDir>/config and hooks/ protected.
What you ruled out
- Creating a branch and
git stash pushsucceed in the same thread, so the git dir is partly writable; only ref deletion fails. git fetch --prune originsucceeded, but there was nothing to prune, so it neither confirms nor rules out the same failure.- Not the permission-profile problem in feat(codex): select named permission profiles in execution controls #2524: the default workspace permissions are in effect here.
Suggested priority and effort (optional)
Every Codex worktree thread that deletes a branch needs an unsandboxed retry or an approval. The stash case fails silently and leaves a stray ref. The change is to one function.
Checks
- I reproduced this on the latest release or on
main, or I say above that I could not. - I searched open and closed issues for the same problem.
- If an agent wrote this, the body ends with
> AGENT GENERATEDand links the thread or report.
Reproduced by an agent in a local bb thread; the thread is not publicly linkable.
AGENT GENERATED
Activity
SawyerHood commentedon Sep 30, 2026
Verified configuration report: https://get-bb.github.io/reports/issues/4488.html
PARTIALLY REPRODUCED in two clean checkouts. Synthetic attached and detached worktree metadata yields additional write-root lists that omit packed-ref and stash paths; JSON config and typed policy agree. No policy was applied and no Codex/Git operations were run, so native sandbox enforcement and reported branch/stash outcomes remain unverified. Both-run evidence and controls are included.
Ernxst commentedon Sep 30, 2026
Following up on the verification report: this checks the part it left unverified, sandbox enforcement in a live Codex thread.
The run used a Codex thread (
--new-environment worktree, permission modeaccept-edits) on a fresh scratch repository, with bb 0.43.4, Codex CLI 0.157.1, git 2.50.1 (Apple Git-155) and macOS. Every command ran inside the sandbox without escalation. The path probe needed one command approval, allowed once with no extra permissions; itsdenylines show it still ran sandboxed.Writable roots the thread received, git entries only (the others are the worktree,
/private/tmp,$TMPDIRand bb thread storage):These include all of
<commonDir>/refsand<commonDir>/logs, which is more than the report's fixture produced. The common directory itself is still not a root.Creating and then removing a file at each common-dir path, on branch
refs/heads/bb/<name>:The two ref commands in the same thread:
packed-refs.lockis the only path the ref commands need that the sandbox denies, and both failures name it.configstays protected. Sincerefs/andlogs/are already writable in a live thread, the missing write is narrower than the issue body suggests:<commonDir>/packed-refs.lockand its rename over<commonDir>/packed-refs. Whether allowing those two paths is enough is not tested here.dimiboi commentedon Nov 24, 2026
One more manifestation on bb desktop/CLI 0.50.1, macOS 26.7.1 arm64, Codex CLI 0.172.0, and Git 2.54.0 (Apple Git-157). In a BB-managed linked worktree,
git commitprinted the error below, returned 0, and advancedHEAD. Expected a successful commit without the lock error.The managed workspace-write scope included the shared
objects,refs, andlogsdirectories and the worktree’s private Git directory. It omitted the common Git directory and the lock path. No lock file was present when inspected.I reproduced the exact stderr, exit status, and HEAD change in a disposable files-backend linked worktree. A normal
git commit --allow-empty -m probewas clean. Withchflags uchgapplied to the disposable common Git directory, the same command printed the error and still advanced HEAD (git rev-parse HEADbefore and after). I cleared the flag and removed the scratch repository. This isolates the Git behavior under denied lock creation. I did not retest the commit on a BB build containing #7994.