macOS workspace-write sandbox denies directory rename and removal inside a writable workspace
What version of Codex CLI is running?
codex-cli 0.149.1
What subscription do you have?
ChatGPT Pro 5x
Which model were you using?
gpt-5.6-terra medium
What platform is your computer?
Darwin 25.5.0 arm64 arm
What terminal emulator and version are you using (if applicable)?
No response
Codex doctor report
{
"schemaVersion": 1,
"generatedAt": "1787640983s since unix epoch",
"overallStatus": "ok",
"codexVersion": "0.149.1",
"checks": {
"app_server.status": {
"id": "app_server.status",
"category": "app-server",
"status": "ok",
"summary": "background server is not running",
"details": {
"control socket": "/Users/rklos/.codex/app-server-control/app-server-control.sock",
"daemon state dir": "/Users/rklos/.codex/app-server-daemon",
"mode": "ephemeral",
"pid file": "/Users/rklos/.codex/app-server-daemon/app-server.pid (missing)",
"settings": "/Users/rklos/.codex/app-server-daemon/settings.json (missing)",
"status": "not running",
"update-loop pid file": "/Users/rklos/.codex/app-server-daemon/app-server-updater.pid (missing)"
},
"remediation": null,
"durationMs": 0
},
"auth.credentials": {
"id": "auth.credentials",
"category": "auth",
"status": "ok",
"summary": "auth is configured",
"details": {
"auth file": "/Users/rklos/.codex/auth.json",
"auth storage mode": "File",
"stored API key": "false",
"stored ChatGPT tokens": "true",
"stored agent identity": "false",
"stored auth mode": "chatgpt"
},
"remediation": null,
"durationMs": 0
},
"config.load": {
"id": "config.load",
"category": "config",
"status": "ok",
"summary": "config loaded",
"details": {
"CODEX_HOME": "/Users/rklos/.codex",
"config.toml": "/Users/rklos/.codex/config.toml",
"config.toml parse": "ok",
"cwd": "/Users/rklos",
"enabled feature flags": "shell_tool, view_image, unified_exec, shell_snapshot, code_mode_host, terminal_resize_reflow, sqlite, hooks, request_permissions_tool, enable_request_compression, unbounded_connection_retries, multi_agent, apps, tool_search_always_defer_mcp_tools, tool_suggest, plugins, in_app_browser, in_app_chat, in_app_dictation, in_app_updates, browser_use, browser_use_full_cdp_access, browser_use_external, computer_use, remote_plugin, plugin_sharing, image_generation, resize_all_images, item_ids, skill_mcp_dependency_install, skill_search, mentions_v2, steer, guardian_approval, goals, collaboration_modes, tool_call_mcp_elicitation, auth_elicitation, personality, fast_mode, tui_app_server, remote_compaction_v2, workspace_dependencies",
"feature flag overrides": "request_permissions_tool=true",
"feature flags enabled": "43",
"log dir": "/Users/rklos/.codex/log",
"mcp servers": "3",
"model": "gpt-5.6-terra",
"model provider": "openai",
"sqlite home": "/Users/rklos/.codex"
},
"remediation": null,
"durationMs": 0
},
"git.environment": {
"id": "git.environment",
"category": "git",
"status": "ok",
"summary": "git version 2.50.1 (Apple Git-155)",
"details": {
"PATH git #1": "/usr/bin/git",
"PATH git entries": "1",
"git build options": "git version 2.50.1 (Apple Git-155); cpu: arm64; no commit associated with this build; sizeof-long: 8; sizeof-size_t: 8; shell-path: /bin/sh; feature: fsmonitor--daemon; libcurl: 8.7.1; zlib: 1.2.12; SHA-1: SHA1_DC; SHA-256: SHA256_BLK",
"git exec path": "/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core",
"git version": "git version 2.50.1 (Apple Git-155)",
"repo detected": "false",
"selected git": "/usr/bin/git"
},
"remediation": null,
"durationMs": 166
},
"installation": {
"id": "installation",
"category": "install",
"status": "ok",
"summary": "installation looks consistent",
"details": {
"PATH codex #1": "/Users/rklos/.local/bin/codex",
"current executable": "/Users/rklos/.local/bin/codex",
"install context": "standalone (unix, package /Users/rklos/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin, bin /Users/rklos/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/bin, resources /Users/rklos/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/codex-resources, path /Users/rklos/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/codex-path)",
"managed by bun": "false",
"managed by npm": "false",
"managed by pnpm": "false",
"managed package root": "not set"
},
"remediation": null,
"durationMs": 2
},
"mcp.config": {
"id": "mcp.config",
"category": "mcp",
"status": "ok",
"summary": "MCP configuration is locally consistent",
"details": {
"configured servers": "3",
"disabled servers": "0",
"stdio servers": "2",
"streamable_http servers": "1"
},
"remediation": null,
"durationMs": 515
},
"network.env": {
"id": "network.env",
"category": "network",
"status": "ok",
"summary": "network-related environment looks readable",
"details": {
"managed proxy": "not configured",
"proxy env vars": "none",
"respect system proxy": "disabled",
"system proxy": "direct"
},
"remediation": null,
"durationMs": 0
},
"network.provider_reachability": {
"id": "network.provider_reachability",
"category": "reachability",
"status": "ok",
"summary": "active provider endpoints are reachable over HTTP",
"details": {
"ChatGPT inference URL": "https://chatgpt.com/backend-api/<redacted> reachable (HTTP 405)",
"reachability mode": "ChatGPT auth"
},
"remediation": null,
"durationMs": 282
},
"network.websocket_reachability": {
"id": "network.websocket_reachability",
"category": "websocket",
"status": "ok",
"summary": "Responses WebSocket handshake succeeded",
"details": {
"DNS": "2 IPv4, 0 IPv6, first IPv4",
"auth mode": "chatgpt",
"connect timeout": "15000 ms",
"endpoint": "wss://chatgpt.com/backend-api/<redacted>",
"handshake result": "HTTP 101 Switching Protocols",
"model provider": "openai",
"provider name": "OpenAI",
"proxy env vars": "none",
"reasoning header": "false",
"server model present": "false",
"supports websockets": "true",
"wire API": "responses"
},
"remediation": null,
"durationMs": 911
},
"runtime.provenance": {
"id": "runtime.provenance",
"category": "runtime",
"status": "ok",
"summary": "running standalone on macos-aarch64",
"details": {
"commit": "unknown",
"current executable": "/Users/rklos/.local/bin/codex",
"install method": "standalone (unix, package /Users/rklos/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin, bin /Users/rklos/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/bin, resources /Users/rklos/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/codex-resources, path /Users/rklos/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/codex-path)",
"platform": "macos-aarch64",
"version": "0.149.1"
},
"remediation": null,
"durationMs": 0
},
"runtime.search": {
"id": "runtime.search",
"category": "search",
"status": "ok",
"summary": "search is OK (bundled)",
"details": {
"search command": "/Users/rklos/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/codex-path/rg",
"search command readiness": "file exists",
"search provider": "bundled"
},
"remediation": null,
"durationMs": 0
},
"sandbox.helpers": {
"id": "sandbox.helpers",
"category": "sandbox",
"status": "ok",
"summary": "sandbox configuration is readable",
"details": {
"approval policy": "OnRequest",
"codex-linux-sandbox helper": "none",
"execve wrapper helper": "/Users/rklos/.codex/tmp/arg0/codex-arg0QKBOua/codex-execve-wrapper",
"filesystem sandbox": "restricted",
"network sandbox": "enabled"
},
"remediation": null,
"durationMs": 0
},
"security.endpoint": {
"id": "security.endpoint",
"category": "security",
"status": "ok",
"summary": "no supported endpoint protection detected",
"details": {
"endpoint products": "none detected"
},
"remediation": null,
"durationMs": 19
},
"state.paths": {
"id": "state.paths",
"category": "state",
"status": "ok",
"summary": "state paths and databases are inspectable",
"details": {
"CODEX_HOME": "/Users/rklos/.codex (dir)",
"active rollout files": "124 files, 1215244917 total bytes, 9800362 average bytes",
"archived rollout files": "0 files, 0 total bytes, 0 average bytes",
"goals DB": "/Users/rklos/.codex/goals_1.sqlite (file)",
"goals DB integrity": "ok",
"log DB": "/Users/rklos/.codex/logs_2.sqlite (file)",
"log DB integrity": "ok",
"log dir": "/Users/rklos/.codex/log (missing)",
"memories DB": "/Users/rklos/.codex/memories_1.sqlite (file)",
"memories DB integrity": "ok",
"queue DB": "/Users/rklos/.codex/queue_1.sqlite (file)",
"queue DB integrity": "ok",
"sqlite home": "/Users/rklos/.codex (dir)",
"standalone release cache": "6 entries in /Users/rklos/.codex/packages/standalone/releases",
"state DB": "/Users/rklos/.codex/state_5.sqlite (file)",
"state DB integrity": "ok",
"thread history DB": "/Users/rklos/.codex/thread_history_1.sqlite (file)",
"thread history DB integrity": "ok"
},
"remediation": null,
"durationMs": 578
},
"state.rollout_db_parity": {
"id": "state.rollout_db_parity",
"category": "threads",
"status": "ok",
"summary": "rollout files and state DB thread inventory agree",
"details": {
"default model provider": "openai",
"rollout DB active files": "124",
"rollout DB active rows": "124",
"rollout DB archive mismatches": "0",
"rollout DB archived files": "0",
"rollout DB archived rows": "0",
"rollout DB duplicate DB paths": "0",
"rollout DB duplicate rollout thread ids": "0",
"rollout DB malformed file names": "0",
"rollout DB missing active rows": "0",
"rollout DB missing archived rows": "0",
"rollout DB model providers": "openai=124",
"rollout DB rows": "124",
"rollout DB scan cap reached": "false",
"rollout DB scan errors": "0",
"rollout DB sources": "subagent:thread_spawn=67, cli=49, exec=8",
"rollout DB stale rows": "0"
},
"remediation": null,
"durationMs": 270
},
"system.disk": {
"id": "system.disk",
"category": "disk",
"status": "ok",
"summary": "sufficient free disk space (142.2 GiB)",
"details": {
"CODEX_HOME available": "142.2 GiB",
"failure threshold": "1.0 GiB",
"warning threshold": "5.0 GiB",
"worktree available": "142.2 GiB"
},
"remediation": null,
"durationMs": 0
},
"system.environment": {
"id": "system.environment",
"category": "system",
"status": "ok",
"summary": "OS language en-GB",
"details": {
"EDITOR": "not set",
"LANG": "en_GB.UTF-8",
"LESS": "set",
"PAGER": "set",
"VISUAL": "not set",
"os": "Mac OS 26.5.2 [64-bit]",
"os language": "en-GB",
"os type": "Mac OS",
"os version": "26.5.2"
},
"remediation": null,
"durationMs": 2
},
"terminal.env": {
"id": "terminal.env",
"category": "terminal",
"status": "ok",
"summary": "terminal metadata was detected",
"details": {
"COLORFGBG": "7;0",
"COLORTERM": "truecolor",
"TERMINFO_DIRS entry": [
"/Applications/iTerm.app/Contents/Resources/terminfo (dir)",
"/usr/share/terminfo (dir)"
],
"TERM_PROGRAM": "iTerm.app",
"color output": "enabled",
"effective locale": "en_GB.UTF-8",
"stderr is terminal": "true",
"stdin is terminal": "true",
"stdout is terminal": "true",
"terminal": "iTerm2",
"terminal size": "150x30",
"terminal version": "3.6.11"
},
"remediation": null,
"durationMs": 0
},
"terminal.title": {
"id": "terminal.title",
"category": "title",
"status": "ok",
"summary": "terminal title default",
"details": {
"terminal title activity": "true",
"terminal title items": "activity, project-name",
"terminal title project source": "cwd",
"terminal title project value": "rklos",
"terminal title source": "default"
},
"remediation": null,
"durationMs": 0
},
"updates.status": {
"id": "updates.status",
"category": "updates",
"status": "ok",
"summary": "update configuration is locally consistent",
"details": {
"cached latest version": "0.149.1",
"check for update on startup": "true",
"last checked at": "2026-08-24T18:30:57.563239Z",
"latest version": "0.149.1",
"latest version status": "current version is not older",
"update action": "standalone installer",
"version cache": "/Users/rklos/.codex/version.json"
},
"remediation": null,
"durationMs": 218
}
}
}
What issue are you seeing?
File creation works, but directory removal and rename operations return EPERM even though:
- the workspace is declared writable;
- source and destination are inside that workspace;
- ownership and POSIX permissions are normal;
- the target directory is empty;
- the same command succeeds in the normal macOS Terminal.
Error: EPERM: operation not permitted, rmdir '<workspace>/.next/build/chunks'
mv: rename visualizations-v2 to docs/designs/visualizations-v2: Operation not permitted
What steps can reproduce the bug?
Use any writable Git workspace.
-
Run a Next.js build in Codex:
npm run buildThe first build succeeds and creates.next. -
Run the same command again in the same Codex session:
npm run build -
It fails before compilation:
Error: EPERM: operation not permitted, rmdir '<workspace>/.next/build/chunks' -
Moving a directory inside the same workspace also fails. The destination does not exist before the command:
mv visualizations-v2 docs/designs/visualizations-v2Result:mv: rename visualizations-v2 to docs/designs/visualizations-v2: Operation not permitted -
Changing Next's
distDirfrom.nextto a regular directory such as next-build does not help. The second build fails in the same way:Error: EPERM: operation not permitted, rmdir '<workspace>/next-build/build/chunks'
What is the expected behavior?
Commands running in workspace-write should be able to create, remove, and rename files and directories inside the writable workspace.
Additional information
- Running the build with
danger-full-accesssucceeds twice in a row. - The failure is independent of the .next directory name.
- Adding
.next/**as an explicit writable path in the permissions profile did not help. - The standalone installation layout uses the
currentsymlink shown above. - Launching Codex through the fully resolved release binary allowed the Next.js part of the build to complete under workspace-write, which may indicate a macOS Seatbelt issue involving the standalone symlink path.
Related issues
- #38286: macOS standalone apply_patch helper fails through the current symlink with EPERM
- #28894: workspace-write on macOS returns EPERM for operations that work with danger-full-access
- #20613: macOS Seatbelt handling of writable roots has known regressions
I can reproduce this on:
- Codex CLI
0.152.0 - macOS
15.2, Apple Silicon (arm64) - a managed custom permission profile that extends
:workspace
Additional evidence:
- Creating and modifying files inside the writable workspace succeeds.
- Removing an empty directory inside the same workspace fails with
EPERM. - A subsequent Next.js build fails while removing
.next/build/chunks. - Gradle
cleanfails while deleting the workspacebuild/directory; later compilation can also fail while replacing directories belowbuild/classes. - The filesystem watcher also reported that it could not start the FSEvents stream.
Approval does not provide a usable fallback in this configuration. I changed the policy to approval_policy = "on-request", requested escalation for the exact command /bin/rm -rf -- <workspace>/fe/.next, and approved it in the UI. Codex recorded the approval and saved the exact prefix, but the command still ran with the effective restriction and returned EPERM for the directories.
After switching the global default to :danger-full-access and removing the project permission profile, the same workspace mkdir/rmdir probe succeeds immediately. This rules out ownership and ordinary POSIX permissions on the repository.
Feedback thread with attached session diagnostics: 01a05fcb-cbee-7b00-bcc1-c1d8c02bfa23.
Additional reproduction and source-level evidence, without changing the secret-file protections.
Environment:
- Codex Desktop 26.901.41600, build 7982, macOS.
- The affected task's session metadata reports Codex CLI 0.153.4.
- Node.js 22.22.1 and pnpm 10.32.1.
- A custom permission profile extending
:workspace, with recursive.envdeny rules under:workspace_rootsandapproval_policy = "on-request".
Observed behavior in the task's assigned writable Git worktree:
- A frozen production install, with lifecycle scripts and pnpmfile hooks disabled, downloaded/cached 92 packages but remained at
added 0. It was interrupted after about 15 minutes. - One bounded offline attempt with
PNPM_MAX_WORKERS=1reused all 92 packages, downloaded none, and again remained atadded 0; it was stopped after 180 seconds. - A single request to the unchanged pnpm
worker.jsimport function reproduced a narrower boundary, without running the full installer or using the network. Two small, generated, non-secret files were copied into a staging directory and matched their source bytes. Renaming that directory to its final sibling name raisedEPERM. - The same 30-second diagnostic was executed once through the standard
require_escalatedapproval path. It also copied the files and then raisedEPERMon the directory rename. This was a runtime failure, not an approval-review rejection.
The probe only logged and rethrew the original renameSync result/error; it did not alter the installed pnpm code. Both probes ended at their 30-second bound. Source files, manifests, and the lockfile remained unchanged. No secret file was read, and no protection was removed.
Relevant public implementation: build_seatbelt_unreadable_glob_policy at pinned commit 6af3454. It creates directory file-write-unlink denies for ancestors of unreadable glob patterns. For a workspace-scoped **/.env pattern, its ** ancestor appears to cover every descendant directory, including generated dependency staging directories that contain no secret files.
This source-level explanation is consistent with the observations; I have not verified that the installed binary was built from that exact public commit, or that every earlier install stall had the same cause.
Is there a supported remediation or planned fix that preserves recursive secret-file denial while allowing ordinary package-manager staging directories to be finalized? A fix should retain protection against moving actual protected descendants outside their denied paths. Full disk access or removal of the .env protections would not meet that requirement.
Independent reproduction, adding a pytest-specific impact and a generic fixed-name control.
Environment:
- Codex Desktop
26.901.51231(build8109) - Codex CLI
0.153.4 - macOS
26.6.2(25G83), arm64 - managed
workspace-writeprofile - the workspace and
<repo>/.pytest_cacheare explicitly writable - recursive
**/.envdeny rules are active beneath the workspace roots
Generic control inside the writable repository root:
from pathlib import Path
source = Path("codex-sandbox-dir-probe-source")
target = Path("codex-sandbox-dir-probe-target")
source.mkdir() # succeeds
source.rename(target) # PermissionError: [Errno 1] Operation not permitted
source.rmdir() # PermissionError: [Errno 1] Operation not permitted
The names are unrelated to protected paths or dot-directories. Ownership and POSIX mode are normal. The identical create/rename/remove sequence succeeds under /private/tmp.
This causes an accumulating artifact leak with pytest 9.1.1. Pytest atomically initializes .pytest_cache by:
- creating
<repo>/pytest-cache-files-<random>; - writing its cache support files;
- renaming that directory to
.pytest_cache; - best-effort removing the staging directory in
finally.
Inside this sandbox, step 3 returns EPERM, and step 4 also returns EPERM. Repeated test runs had accumulated 24 empty pytest-cache-files-* directories before diagnosis. A direct reproducer produced:
PermissionError: [Errno 1] Operation not permitted:
'<repo>/pytest-cache-files-2pync2lo' -> '.pytest_cache'
Adding or retaining .pytest_cache as an explicit writable root does not address the underlying rename/unlink denial. Pre-creating .pytest_cache outside the sandbox avoids pytest's initialization path only until that cache directory is removed.
This independently supports the recursive unreadable-glob / ancestor file-write-unlink explanation in the previous comment and demonstrates that the defect affects Python tooling as well as Node/Gradle workflows.
Empty-directory removal still fails on Desktop's bundled CLI 0.153.4. A disposable workspace tested from a normal terminal with codex sandbox -P workspace-hardened --include-managed-config -C <workspace> produced:
File creation/deletion: OK
rmdir: pkgs/by-name/zz/probe: Operation not permitted
Sandbox exit: 1
Normal-terminal rmdir: OK
A successful Git fast-forward in Codex Desktop left 207 empty Nixpkgs package directories, breaking nix-shell evaluation. The macOS session used CLI 0.150.0-alpha.12.2 with a managed workspace-write profile and recursive deny patterns such as <repo>/**/*.key.
All 207 directories had tracked files before the merge and none afterward. Later, read-only sandbox_check() probes found file-write-unlink denied for every empty directory but allowed for an ordinary package file.
This is consistent with the ancestor unlink-deny generation identified above: the ** ancestor covers descendant directories, including empty ones. Git silently stops directory cleanup when rmdir() fails, allowing the merge to report success. Empty directories do not appear in Git status.
Nixpkgs discovers packages from directory names without first checking for package.nix. Leftover brave and spice-gtk directories therefore generated attributes conflicting with existing definitions.
Removing the 207 verified-empty directories using rmdir in a normal terminal restored evaluation: staged and unstaged diffs were unchanged, no empty package directories remained, and nix-shell --run 'echo "nix-shell OK"' succeeded. The deny rules remained intact.
The historical rmdir() result was not retained, and the historical binary's equivalence to the linked source is unverified; sandbox causation remains an evidence-supported inference.
a fix or supported mitigation should cover successful Git operations leaving broken checkouts while preserving denied-file restrictions and protection against moving protected descendants outside their denied paths
Additional independent reproduction with root-cause isolation, using codex sandbox directly (no LLM loop involved), on codex-cli 0.154.0 (also reproduced identically on 0.153.4).
Setup: a permission profile extending :workspace with the stock recursive secret-file deny globs under :workspace_roots (e.g. **/dotenv-file, **/*.pem, **/id_rsa, **/dot-ssh/**, etc. — the standard credential-file patterns), approval_policy = "on-request".
Repro (workspace root /home/user, target dir freshly created and empty/non-secret):
$ codex sandbox -C /home/user/project -P workspace-no-secrets --log-denials -- mkdir sub
exit=0, no denials
$ codex sandbox -C /home/user/project -P workspace-no-secrets --log-denials -- rmdir sub
rmdir: sub: Operation not permitted
=== Sandbox denials ===
(rmdir) file-write-unlink /home/user/project/sub
exit=1
Same result for mv (rename) and rm -rf on a directory that contains only harmless files.
Isolation of cause: the same commands succeed (exit 0, no denials) under two control conditions:
- A profile extending
:workspacewith no secret-file deny globs at all. - A profile with a secret-file deny expressed as a literal absolute path (no
*/**), e.g.filesystem = { "/home/user/project/known-secret-file" = "deny" }.
Only recursive glob patterns (containing **) under :workspace_roots trigger the blanket file-write-unlink deny on every directory in the workspace tree — regardless of whether any file actually matching the glob exists anywhere near the target directory.
Source-level confirmation on main: the ancestor-deny generator (in codex-rs/sandboxing/src/seatbelt.rs, the function building denies from :workspace_roots unreadable-glob patterns) iterates Path::ancestors() of the glob pattern string itself and emits a (deny file-write-unlink (require-all (vnode-type DIRECTORY) (regex #"..."))) rule per ancestor. For a **-containing pattern this collapses to a regex matching effectively every directory under the workspace root, independent of whether any real file matches. This still reproduces against the current main branch as of 2026-09-12.
Impact: any permission profile that protects credential files at arbitrary depth (the documented/expected way to write these rules) makes ordinary directory operations — mkdir+mv, rm -rf on build output, git worktree moves, package-manager installs that stage-then-rename a directory — fail across the entire workspace-write tree, even after explicit escalated approval, with no workaround short of dropping recursive credential-file protection entirely.
Suggested direction for a fix: derive ancestor-deny rules from the concrete directories that can contain a real match (i.e. only ancestors up to the point where a wildcard segment starts, or ancestors of files that actually exist and match), rather than from Path::ancestors() of the pattern string. Happy to help verify a candidate fix against the repro above if useful.
Additional isolation on macOS with codex sandbox directly shows the trigger is broader than recursive ** patterns.
Environment:
- Codex CLI
0.154.0 - macOS, Apple Silicon
- isolated
CODEX_HOME - each test profile extends
:workspace - probe creates a new empty directory in the workspace root, renames it to a sibling, then removes it
Results:
| Added filesystem rule | Result |
|---|---|
| no additional rule | pass |
":minimal" = "read" |
pass |
root-relative exact ".env" = "deny" |
pass |
root-relative glob "*.env" = "deny" |
pass |
nested exact "nested/.env" = "deny" |
pass |
absolute nested exact path = "deny" |
pass |
"**/*.env" = "deny" |
rename fails with EPERM |
"**/.env" = "deny" |
rename fails with EPERM |
"*/*.env" = "deny" |
rename fails with EPERM |
"*/.env" = "deny" |
rename fails with EPERM |
recursive rules plus glob_scan_max_depth = 6 |
rename fails with EPERM |
The failing profiles reject an unrelated root-level rename such as:
mv: rename .codex-profile-probe-source to .codex-profile-probe-target: Operation not permitted
So, in this matrix, every tested workspace-root deny glob containing both a wildcard and a path separator caused the unrelated file-write-unlink failure. The behavior is not specific to **. Exact nested deny paths remain safe.
This also means the documented fixed-depth alternative (*.env, */*.env, */*/*.env, etc.) does not avoid the defect on this macOS build once the pattern contains /. glob_scan_max_depth does not help here either.
Current safe workaround is limited to root-level globs plus enumerated exact nested paths, for example:
[permissions.dev-workspace.filesystem.":workspace_roots"]
".env" = "deny"
"*.env" = "deny"
"apps/example/.env" = "deny"
This preserves normal directory rename/removal, but it cannot express generic nested secret protection. These results strengthen the earlier ancestor-unlink-policy diagnosis and narrow the regression test needed: fixed-depth wildcard path segments must be covered in addition to recursive ** patterns.
I can reproduce this with Codex CLI 0.160.0 using a custom permission profile extending :workspace.
Configuration that triggers the failure:
default_permissions = "workspace-no-env"
[permissions.workspace-no-env]
extends = ":workspace"
[permissions.workspace-no-env.filesystem.":workspace_roots"]
".git" = "write"
"**/.env" = "deny"
"**/.env*.local" = "deny"
"**/.env*.production" = "deny"
"**/.env*.staging" = "deny"
Creating files and directories succeeds, but removing an empty directory inside the writable workspace fails with EPERM. Builds also fail when cleaning generated directories.
The same operations succeed in a normal terminal and in a fresh Codex session using default_permissions = ":workspace".
I’ve temporarily replaced the recursive rules with root-level patterns while waiting for a fix. This reduces protection because nested environment files are no longer covered. I need to preserve secret-file denial at every directory level while allowing ordinary directory rename and removal operations.
Will a fix be there soon?
Additional isolation from 2026-10-11: reproduced on Codex CLI 0.162.0 and the desktop-bundled CLI 0.162.0-alpha.17.2 on macOS.
These tests used disposable directories and empty secret-shaped fixtures, with per-run named permission profiles. No secret contents were read.
The profile allowed workspace and both temporary roots. Its base extended :read-only, with broad filesystem read access and added deny rules. On the PATH CLI, each of these global deny expressions independently caused empty-directory rmdir to fail with EPERM in all three writable roots:
/**/.*_history, /**/.env.*, /**/*.jks, /**/*.keystore, /**/*.p8, /**/credentials*.json, /**/secrets*.json, /**/*.key, /**/*.p12, /**/*.pfx.
Controls: no added denials, exact-path denials, and the global literal-basename denials /**/.env and /**/key.properties permitted cleanup. Ordinary file unlink succeeded even with the failing rules.
After removing only those ten rules, both installed engines permitted directory rename/removal in the workspace and temporary roots; opens of empty .env and key.properties fixtures remained denied. This narrows the distinction between global literal-basename rules and wildcard-basename rules on these versions. The earlier workspace-relative results should not be generalized to these global patterns.
The current public build_seatbelt_unreadable_glob_policy implementation is consistent with ancestor directory-unlink denies and a global literal-basename optimization. The exact source revisions of the installed binaries were not established.
The temporary mitigation reduces native protection for wildcard cases; command hooks provide only partial coverage. A vendor fix should preserve secret-read denial and relocation protection while allowing unrelated directory cleanup and renames.
Additional reproduction on Codex CLI 0.162.1, macOS 26.5.1 (Apple Silicon). This matches the distinction described above between global literal-basename rules and wildcard-basename rules.
A standalone codex sandbox probe creates an unrelated empty directory, then attempts /bin/rmdir. Each condition starts with :workspace and adds just the indicated global deny rule. Managed requirements are excluded from these explicit-profile probes (no --include-managed-config). No private configuration or credential contents are used.
| Added deny expression | Exit code | Empty directory remains |
|---|---|---|
| none | 0 | no |
/**/.env |
0 | no |
/**/credentials.json |
0 | no |
/**/*.env |
1 (EPERM) | yes |
/**/.env.* |
1 (EPERM) | yes |
/**/*.pem |
1 (EPERM) | yes |
/**/*.key |
1 (EPERM) | yes |
/**/secrets/** |
1 (EPERM) | yes |
/**/secrets |
0 | no |
Separately, the same wildcard rules delivered in system requirements.toml reproduced failures when re-installing existing node_modules (npm ci --offline --ignore-scripts), rebuilding an existing .next (next build --webpack), and deleting dist with rimraf. Replacing those rules with enumerated global literal basenames and /**/secrets allowed all three operations and a Git branch switch to complete without leftover directories on this machine. Access predicates for empty fixtures with listed secret names and a nested descendant of secrets remained denied; controls without the managed policy were readable. This temporary workaround does reduce automatic coverage for unlisted secret names and arbitrary key files.
Versions of the disposable development fixture: Node.js 24.13.0, npm 11.6.2, Next.js 16.4.0, React 19.3.0, rimraf 6.1.3. These results do not establish a fix for workspace-relative glob rules, other operating systems, or other Codex versions.
Expected behavior: denying secret-file reads should still allow removing an unrelated empty directory in a writable workspace.
Minimal standalone reproducer (Python 3; run outside another sandbox with Codex CLI on PATH):
#!/usr/bin/env python3
"""Compare unrelated directory removal with global literal/wildcard deny rules."""
import json
from pathlib import Path
import subprocess
import tempfile
patterns = [None, "/**/.env", "/**/credentials.json", "/**/*.env", "/**/.env.*", "/**/*.pem", "/**/*.key", "/**/secrets/**", "/**/secrets"]
root = Path(tempfile.mkdtemp(prefix="codex-unlink-repro-"))
rows = []
for i, pattern in enumerate(patterns):
workspace = root / str(i)
workspace.mkdir()
target = workspace / "ordinary-empty-dir"
target.mkdir()
config = 'permissions.repro={extends=":workspace"'
if pattern:
config += ',filesystem={' + json.dumps(pattern) + '="deny"}'
config += '}'
command = ["codex", "sandbox", "-C", str(workspace), "-P", "repro", "-c", config, "--", "/bin/rmdir", str(target)]
result = subprocess.run(command, capture_output=True, text=True)
rows.append({"pattern": pattern, "exit_code": result.returncode, "remaining": target.exists(), "stderr": result.stderr.replace(str(root), "<fixture>")})
print(json.dumps(rows, indent=2))
# Only remove our disposable empty fixtures, outside the Codex test sandbox.
for workspace in root.iterdir():
target = workspace / "ordinary-empty-dir"
if target.exists():
target.rmdir()
workspace.rmdir()
root.rmdir()
Subject: Protected .env globs block unrelated fixture directory operations on macOS — issue #40565
Environment: Codex CLI 0.164.0 on macOS Apple Silicon, with a filesystem-restricted session. The policy denies access by default, allows writes inside one workspace, disables network access, and denies recursive patterns **/*.env, **/.env* and **/*.env.*.
Observed behavior: existing tests receive EPERM when removing or renaming their own generated fixture directories inside the writable workspace. This prevents completion of the full validation suite. No access to secret files is requested, and denied operations have not been retried through another mechanism.
Source inspection shows that build_seatbelt_unreadable_glob_policy generates directory file-write-unlink denies for ancestors of unreadable glob patterns. These ancestor rules can cover unrelated fixture directories. This is consistent with the observed failures, but we have not independently verified the installed binary’s exact source commit or produced a standalone reproduction.
Is there a supported solution that permits legitimate operations on unrelated fixture directories while preserving protection for matching files, including files created after process startup and attempts to move protected files outside the denied scope?
Disabling the sandbox, removing the .env protections, or protecting only files that currently exist would not meet our requirements.
Reference: https://github.com/openai/codex/issues/40565.
Additional reproduction: recursive deny glob causes rmdir to fail on macOS
I reproduced a related file-write-unlink denial using Codex CLI's custom permission profiles.
Environment
- macOS, Apple Silicon
- Codex CLI 0.167.0 (initially tested; subsequent version not independently confirmed)
- Named permission profiles
- Reproduced directly using
codex sandbox, without involving the AI agent
Working configuration
[permissions.workspace-test]
extends = ":workspace"
[permissions.workspace-test.filesystem]
":root" = "deny"
":minimal" = "read"
With this configuration, creating and removing a directory inside the workspace succeeds.
Failing configuration
Adding just one workspace-relative recursive deny rule:
[permissions.workspace-test.filesystem.":workspace_roots"]
"**/.env" = "deny"
causes removal of an unrelated directory inside the workspace to fail:
rmdir: transcripts/sandbox-minimal-test: Operation not permitted
The macOS sandbox denial log includes:
(rmdir) file-write-unlink /Users/taor/Documents/Dev/YoutubeScripts/transcripts/Uv2w4VTU-iQ
Important comparison
Replacing the recursive pattern:
"**/.env" = "deny"
with the exact-path rule:
".env" = "deny"
allows rmdir to succeed again.
Adding an explicit workspace write rule:
"." = "write"
did not resolve the failure when the recursive deny pattern was present.
Expected behavior
A rule denying access to .env files should not prevent removal of an unrelated, empty directory within a writable workspace.
Actual behavior
The recursive deny glob appears to interfere with macOS Seatbelt's file-write-unlink permission for unrelated directories.
This may be a different root cause from the original issue, but the resulting directory-removal failure is similar.
It would be useful to investigate how recursive deny patterns under :workspace_roots are translated into macOS Seatbelt rules, particularly for directory unlink operations.
Still reproduces on codex-cli 0.169.0 (macOS 27.2, arm64), the current release, and the code path is unchanged on main (59ac39a).
Minimal repro with codex sandbox, scratch CODEX_HOME, no model call:
[permissions.deny-pem]
extends = ":workspace"
[permissions.deny-pem.filesystem.":workspace_roots"]
"**/*.pem" = "deny"
mkdir -p plain/dir
codex sandbox -P :workspace -- mv plain/dir plain/renamed # exit 0
codex sandbox -P :workspace -- mv plain/renamed plain/dir # exit 0
codex sandbox -P deny-pem -- mv plain/dir plain/renamed # Operation not permitted
As noted above, #47920 only exempts /**/<literal>, and the ancestor rule exists for a real reason (moving a directory that holds a protected file out of the glob's scope). A fix that lets directory moves through while keeping moved matches unreadable wherever a move can put them would keep that property; within the current rules there is no config spelling that keeps non-literal basename denies such as **/*.pem and still allows directory moves.
I tested the root-anchored wildcard case on macOS with the CLI bundled in ChatGPT desktop (0.169.1) and a locally patched Codex CLI (0.169.0-drako.1). This extends the literal-basename case in #47920. The relevant entry in my coding profile was:
[permissions.coding.filesystem."/"]
"**/.env.*.local" = "deny"
Both binaries ran the same Python checks via codex sandbox --permission-profile coding --cd <fixture> -- /usr/bin/python3 ..., using the same profile and a fresh, identically populated workspace for each run. The three protected probes were separate, pre-existing files containing synthetic data. The cleanup directory initially contained only a public .env.example file.
| Operation inside the sandbox | Bundled 0.169.1 | Patched 0.169.0-drako.1 |
|---|---|---|
Read .env.read-probe.local |
PermissionError | PermissionError |
Overwrite .env.write-probe.local |
PermissionError | PermissionError |
Unlink .env.unlink-probe.local |
PermissionError | PermissionError |
Read .env.example |
Allowed | Allowed |
Write allowed.txt |
Allowed | Allowed |
Unlink cleanup-probe/.env.example |
Allowed | Allowed |
Immediately call rmdir("cleanup-probe") on the now-empty directory |
PermissionError | Allowed |
The last row was the only difference across the seven checks. The bundled run exited 1 and the patched run exited 0.
Could the macOS Seatbelt fix in #47920 be extended to root-anchored, recursive basename rules like /**/.env.*.local? The local change recognizes a basename with a literal prefix, one *, and a literal suffix. The basename still matches anywhere after an ancestor move. Scoped and multi-component patterns keep their existing ancestor protections.
For the signed desktop runtime, the regression test I’d like to see is the three protected-file operations continuing to fail while the unrelated empty-directory removal succeeds in the same writable workspace. That would let desktop coding agents finish routine cleanup with secret-file protection enabled.
Additional reproduction on Codex CLI 0.172.0 and macOS 26.7.3, using a custom profile extending :workspace with recursive credential-deny rules under :workspace_roots. The same symptom was observed in Codex Desktop; its bundled runtime version was not verified.
In a fresh CLI session launched from Terminal, creating an empty directory inside the writable repository succeeded, but rmdir failed with Operation not permitted, including after an approved elevated retry. Maven clean verify also failed before tests when removing the root target; a separate Python probe could create an empty directory but not remove it. The same cleanup works in a normal terminal. macOS unified logs recorded Sandbox: java(...) deny(1) file-write-unlink <workspace>/target and a corresponding denial for the Python probe. Ownership and ordinary permissions were normal, with no restrictive ACL or immutable flag visible.
The 0.172.0 Seatbelt implementation generates directory unlink restrictions for ancestors of scoped unreadable globs. This is consistent with the symptoms, but the effective generated policy was not captured, and the triggering rule was not isolated.
Is there a supported way to inspect the effective policy or a planned fix that permits ordinary workspace cleanup while preserving recursive credential protection, including against moving protected files outside their denied scope? No credential protections were removed for this investigation.