Articles / Viewpoints and methods
4 minUsing AI Tools

EPERM: operation not permitted, open — Codex cannot write to a second folder

Fix a Codex EPERM write to a second folder on Windows. A tested permission-profile change adds the output directory while an unlisted folder stays blocked.

Aaron HuangSenior Brand Manager

Reviewed by Aaron Huang · 2026-11-17

EPERM: operation not permitted, open '…\reports\summary.txt'. When a script works in your Codex workspace but fails after you point its output at a neighboring folder, check the writable roots first. This page covers native Windows Codex CLI; if an ordinary PowerShell window also cannot write there, investigate Windows file permissions first.

Why the neighboring folder is blocked

In our reproduction, the :workspace profile allowed writes in the main project but rejected the separate output folder. Adding that specific folder as a workspace root let the same script finish, while a third folder remained blocked.

That comparison establishes one cause of EPERM. The code alone does not establish that every file error comes from the sandbox.

1. Check the actual destination

Run codex --version in PowerShell; the commands here were tested with 0.169.0. In an interactive Codex session, use /status to check the working directory and active permissions. /debug-config helps trace configuration layers. See the official command reference.

For example, C:/work/sales and C:/work/reports are siblings. Opening the first does not automatically make the second writable. An absolute output path identifies the destination; it does not grant access to it.

2. Add the destination to your permission profile

This configuration uses permission profiles. If your configuration currently uses sandbox_mode or [sandbox_workspace_write], identify that older configuration path with the Codex permissions guide before changing systems. Profiles and the older sandbox settings do not compose.

Add or update a named profile in the config.toml your CLI actually loads. Replace the example path with the intended output directory. Keep default_permissions at the top level, before any [table]; update an existing value rather than adding a duplicate key.

default_permissions = "sales-reports"

[permissions.sales-reports]
extends = ":workspace"

[permissions.sales-reports.workspace_roots]
"C:/work/reports" = true

The profile inherits the workspace baseline and adds one directory. Restart the CLI and confirm that this profile is active rather than a different policy selected by launch flags. The official Permissions guide explains profile selection and configuration precedence.

3. Repeat the failing write

Keep the script and output path unchanged. Check that the intended file now exists and contains the correct report. Also verify that the original workspace remains writable.

To test the command boundary without involving a model, run the original script through Codex's command sandbox. This example assumes you already have write-report.cjs, which accepts an output directory as its first argument:

codex sandbox --permission-profile sales-reports --cd "C:/work/sales" -- node "C:/work/sales/write-report.cjs" "C:/work/reports"

On the native Windows 0.169.0 CLI, use codex sandbox directly. Some official examples still show an extra windows subcommand; check your installed codex sandbox --help before copying that older form. Running a script this way does not call a model.

Our script summed three orders, 120, 80 and 50. The baseline profile returned EPERM for the sibling output folder. Adding its workspace root produced Sales total: 250. Using that same updated profile to write to a third, unlisted folder still returned EPERM.

If the write still fails

  • It also fails outside Codex: investigate Windows permissions, a file lock or a read-only destination. A Codex profile does not grant Windows administrator privileges.
  • ENOENT: no such file or directory: make sure the output directory exists. A permission rule does not create missing application directories.
  • An error mentions windows or an executable cannot be found: check the installed sandbox help and use the full executable path where necessary.
  • The active mode differs from your edited configuration: inspect launch flags, configuration layers and managed requirements. Continue with permission mode troubleshooting.

For ad hoc work across repositories, the CLI also exposes --add-dir; consult the official flags. We tested the profile-defined workspace_roots route, which is useful for recurring work with the same output folder.

What we tested

November 16, 2026: native Windows PowerShell, Codex CLI 0.169.0 and Node.js, with isolated configuration and synthetic orders. The actual command sandbox ran one report script against the primary, added and unlisted directories, including the failed write and its fix. No model conversation was run. Desktop, WSL, UNC paths, managed machines and other Windows sandbox implementations were not tested. Official Permissions and Developer commands consulted November 16, 2026.