Fix it
- Look at the path in the error. If it's outside your project folder (a tool's cache in your home folder, such as
~/.cache/uv, is a common example), Codex's sandbox blocked the write. Protected folders inside the project, such as.git, are blocked too. - Quick fix: keep that tool's cache inside the project. For uv, ask Codex to run the command with
UV_CACHE_DIR=.uv-cachein front, for exampleUV_CACHE_DIR=.uv-cache uv venv, from the project folder. - Lasting fix: give Codex write access to your cache folder with a permission profile (below).
- Check it worked: run the same command again. It should finish without the error.
Status:
- Error reproduced on Codex CLI 0.167.0 (the npm
latestrelease, published November 6, 2026 UTC) and on 0.166.0-alpha.6, using Codex'scodex sandboxcommand on macOS. - Both fixes confirmed on both versions.
- Not tested: Linux, Windows, full Codex agent sessions, and Codex's approval prompts.
Why it happens
In its default mode, Codex lets commands write inside your workspace (your project folder) and the system's temporary folders. Some protected folders inside the workspace stay read-only, such as .git and .codex. A write anywhere else is refused by the operating system, and uv reports that as Operation not permitted (os error 1).
What Kingy saw inside the Codex sandbox (same results on both versions):
| What the command did | Result |
|---|---|
| Wrote a file inside the project | Worked |
| Wrote a file outside the project | Operation not permitted |
Wrote a file inside the project's .git folder |
Operation not permitted |
uv venv (uv keeps its cache in ~/.cache/uv) |
Failed to initialize cache at `~/.cache/uv` then failed to create directory `~/.cache/uv`: Operation not permitted (os error 1) (home path shortened to ~) |
Quick fix: keep the cache inside your project
From the project folder, give the tool a cache folder inside the project. For uv:
UV_CACHE_DIR=.uv-cache uv venv
In our test, the uv venv that had failed then worked, on both versions. Add .uv-cache/ to your .gitignore.
Other tools that keep caches in your home folder can fail the same way. Kingy tested uv only.
Lasting fix: a permission profile
Add this to ~/.codex/config.toml. It keeps the normal workspace rules and adds write access to your ~/.cache folder:
default_permissions = "cache-write"
[permissions.cache-write]
extends = ":workspace"
[permissions.cache-write.filesystem]
"~/.cache" = "write"
- In our test (profile selected with
-P cache-write), the failinguv venvworked on both versions. - The
default_permissionsline is what makes this profile the default for your Codex sessions, per OpenAI's permissions guide. Our test chose the profile by name instead. - Extending
:workspacekeeps its built-in protections, such as read-only.gitand.codexfolders, per the same guide.
Want to grant only ~/.cache/uv? That works only if ~/.cache already exists. In our test:
- A profile granting just
"~/.cache/uv"still failed when~/.cachewas missing, because creating the parent folder was blocked. - It worked once
~/.cacheexisted.
Avoid two things:
- Mixing profiles with the older
sandbox_modeor--sandboxsettings. The guide says those switch Codex back to the older system. In our test, the oldersandbox_workspace_write.writable_rootssetting did not lift the block while the:workspaceprofile was active. - Turning on full access just to fix a cache folder. Grant the folder instead.
If Codex asks to run the command outside the sandbox
In the on-request approval mode, Codex asks when a command needs to go beyond the sandbox. OpenAI's sandboxing guide says approvals can cover one run or the rest of the session, depending on the option you pick. Kingy didn't test the approval prompts.
How Kingy tested this
- Setup: we used Codex's own
codex sandboxcommand with the built-in:workspacepermission profile on macOS. Each run had:- a throwaway Codex settings folder (
CODEX_HOME), - a stand-in home folder outside the project,
- no API key.
- a throwaway Codex settings folder (
- No login:
codex login statusreported "Not logged in". - Evidence: the error text above is copied from those runs. The script and both raw logs are kept with this page's evidence.
Related
A GitHub report, Python UV fails in Codex (#1457):
- Filed against codex-cli 0.2.0 on macOS in July 2025, and closed in January 2026.
- Its reporter found that adding
~/.cache/uvto writable roots "had no apparent effect". That was an early version, so it may not describe current Codex.
Sources
- Kingy lab logs, 2026-11-06 (UTC): Codex CLI 0.167.0 and 0.166.0-alpha.6, macOS 26.3.
- OpenAI, Codex permissions. Read 2026-11-06 for:
- profile syntax and
default_permissions, - what the
:workspacebaseline allows, and which folders stay read-only, extendskeeping protections,- not mixing profiles with
sandbox_mode.
- profile syntax and
- OpenAI, Codex sandboxing. Read 2026-11-06 for: Seatbelt on macOS, workspace-write as the default local mode, on-request approvals and approval scopes.
- GitHub, openai/codex #1457. Read 2026-11-06.