Skip to content

Kingy / AI Fix Finder

← All fixes

Codex "Operation not permitted (os error 1)": how to fix it

Check this fix ↓

Codex command fails with Operation not permitted (os error 1)? Often the sandbox blocked a write outside your project. Two fixes Kingy confirmed on Codex 0.167.0, macOS.

kingy tested Checked 2026-11-06

Fix it

  1. 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.
  2. Quick fix: keep that tool's cache inside the project. For uv, ask Codex to run the command with UV_CACHE_DIR=.uv-cache in front, for example UV_CACHE_DIR=.uv-cache uv venv, from the project folder.
  3. Lasting fix: give Codex write access to your cache folder with a permission profile (below).
  4. 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 latest release, published November 6, 2026 UTC) and on 0.166.0-alpha.6, using Codex's codex sandbox command 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 failing uv venv worked on both versions.
  • The default_permissions line 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 :workspace keeps its built-in protections, such as read-only .git and .codex folders, 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 ~/.cache was missing, because creating the parent folder was blocked.
  • It worked once ~/.cache existed.

Avoid two things:

  • Mixing profiles with the older sandbox_mode or --sandbox settings. The guide says those switch Codex back to the older system. In our test, the older sandbox_workspace_write.writable_roots setting did not lift the block while the :workspace profile 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 sandbox command with the built-in :workspace permission profile on macOS. Each run had:
    • a throwaway Codex settings folder (CODEX_HOME),
    • a stand-in home folder outside the project,
    • no API key.
  • No login: codex login status reported "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/uv to 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 :workspace baseline allows, and which folders stay read-only,
    • extends keeping protections,
    • not mixing profiles with sandbox_mode.
  • 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.