A workspace without secrets + settings that refuse reads. Start by combining these two.
Read-only, approval, and training settings each play a different role. Check separately whether they can actually stop access to secret files.
Check reading, running, and sending separately
Remove unneeded secrets from the workspace. Consider the read-refusing deny setting for the target files.
Check who approves. Do not widen the boundary with Full access or permission to run outside the sandbox.
Check command networking, sending to the model, and browser or MCP access separately.
Contents
- 1. Differences between read-only, approval, and training settings
- 2. First separate secrets from the workspace
- 3. Example settings that refuse reads
- 4. .env patterns and easily overlooked scope
- 5. What command networking-off stops and what it doesn't
- 6. Differences in environment variables, OS, and cloud
- 7. Steps to verify with dummy files
- FAQ
1. Differences between read-only, approval, and training settings
"Can't modify a file" and "can't read a file" are different things.
A mode that restricts writes. It is not a feature that blocks reading the contents of files that can be read.
Specifies where edits are allowed. The read scope is not necessarily limited to the same place.
| Control | Mainly decides | What it does not guarantee |
|---|---|---|
| Read-only | Whether files can be modified | That accessible secret files will not be read |
| Approval policy | Who reviews operations that cross the boundary | That reads within the allowed scope will be confirmed by a person each time |
| File deny | Refusing reads and writes to target paths | Removing content already pasted, or access through other tools |
| Command networking limits | Destinations for communication from commands in the sandbox | Stopping all communication from the model, authentication, browser, MCP, and so on |
| Training settings | Whether processed data is used to improve models | Stopping the processing or transmission itself |
on-request still lets commands within the allowed scope run without additional approval. If you want human confirmation, check both the approval policy and who reviews.
Difference from automatic AI review
approvals_reviewer = "auto_review" is a setting that sends review of targets to AI. It is not human confirmation, nor is it a setting that adds review to every operation that was already allowed.
Source: OpenAI: approval and sandbox boundaries. For training, see ChatGPT and Codex training settings and confidential information, which is covered separately.
2. First separate secrets from the workspace
For screen fixes, source code and dummy data may be enough. Production API keys, customer data, and family documents do not need to be in the same environment.
Moving files to another folder is not enough. If broad read permission remains, the moved files may still be reachable.
Working copy: only what is needed
Use a small input that can reproduce the problem instead of production data.
Keep config examples to key names only. Also check logs, backups, and history.
See whether it can reach other folders, the home directory, shared storage, or connected apps.
Can Git ignore settings stop reads?
.gitignore specifies untracked files that Git ignores. It is not a mechanism that removes OS read permission. Even if a search tool usually ignores them, that does not guarantee that reads by direct path are refused. Ignore rules added later also do not take effect for files already tracked by Git. Git official: what gitignore covers.
Difference between instructions and technical refusal
Writing "do not read secrets" in AGENTS.md is useful as a work instruction. However, by itself it does not create an OS-level access restriction. The basic approach is to layer instructions with technical refusal. For concrete examples of anonymizing inputs, see also Precautions when entering information into AI.
3. Example settings that refuse reads
Permission profiles are a beta feature. Check the supported environment and the settings currently selected for the session before using them.
read: ReadPermission to read the target
write: EditAllows writing to the target
deny: DenyRefuses reading and writing the target
Caution when combined with the legacy sandbox settings
If the old settings remain, Permission profiles may not be used.
Check conflicting settings and admin controls
Don't mix with legacy settings: default_permissions and [permissions] are not meant to be used together with the legacy sandbox_mode and [sandbox_workspace_write]. Usually, if the loaded settings contain sandbox_mode, or if --sandbox is passed at startup, the legacy scheme is used. Control through the admin's allowed_permission_profiles is a separate condition.
The following is a sample configuration that combines the official example of limiting the working scope with refusal of secret files and human approval. Do not replace your existing settings wholesale. Check the supported version, organizational constraints, and the execution paths you need, and test in a dummy environment.
Where to write settings: user and project
~/.codex/config.toml
.codex/config.toml
Their scope and loading conditions differ. Project settings are loaded only for trusted projects.
default_permissions = "project-private"
approval_policy = "on-request"
approvals_reviewer = "user"
[permissions.project-private]
extends = ":workspace"
[permissions.project-private.filesystem]
":root" = "deny"
":minimal" = "read"
[permissions.project-private.filesystem.":workspace_roots"]
".env" = "deny"
".env.production" = "deny"
"secrets" = "deny"
[permissions.project-private.network]
enabled = false
Which files does this sample config cover?
Applies to the current workspace and each added workspace
.envDenied target.env.productionDenied targetsecrets/ and belowDenied targetchild-folder/.envCheck separately in this exampleSame secret under another name, or copies in logsCheck separately in this exampleReads are denied with :root. However, :minimal, which is needed for execution, and temporary directories allowed by the inherited base are exceptions.
Inherits :workspace to allow editing, and denies the specific paths above. This is not an example that catches secrets embedded in output.
Notes on setting name, multiple scopes, and temporary files
project-private is the name given in this example. :workspace_roots applies to the current workspace and any added workspaces, and specifies target paths directly under each one. secrets targets the same-named file or subtree.
This is not a configuration that makes everything outside the workspace unreadable. You also need a practice of not copying secrets to temporary areas.
Source: OpenAI: Permission profiles settings, denial, and scope.
4. .env patterns and easily overlooked scope
Exact path specification suits secrets in fixed locations. When using patterns, note that *.env and .env.* are different things. Do not assume that because the official example **/*.env exists, .env.production can be denied under the same condition.
| Example pattern | Intended target | Check separately |
|---|---|---|
.env | Same-named file directly in the workspace root | Child folders, and files whose names have a suffix appended |
.env.production | Production config file directly in the root | Production config under another name, or copies |
secrets | Same-named path directly in the root and below | Copies in other locations, such as logs or backups |
**/*.env | Files whose names end in .env across multiple levels | Names with suffixes; search depth and changes after startup |
Check depth and additions after startup
On Linux, WSL, and native Windows, deny patterns that include unbounded ** may require expansion limited to the scope before startup. The official docs describe either setting glob_scan_max_depth to 1 or higher, or specifying the depth explicitly, as in *.env, */*.env, or */*/*.env. If you use deep levels, you need to check up to that depth.
Files created later may still be readable. According to the official explanation, on Linux, WSL, and Windows (MXC or elevated), files matching deny patterns are enumerated when each process starts. Matching files created while that process is running are not subject to the denial and can be read if other permissions allow it. For example, a shell or dev server that is already running can read a .env created afterward. Because enumeration is repeated when a new process starts, restart running processes after creating a secret file.
When permissions overlap, which takes precedence?
A more specific path designation can override a broader one. For the same path, deny takes precedence, but it is also possible to create a narrow allow inside a broad deny. Also check additional config layers and inheritance from parent profiles.
Sources: OpenAI: denying reads by exact path or glob, config loading order. The project .codex/config.toml is loaded only for trusted projects. Distinguish between what is written in the file and what is effective in the current session.
5. What command networking-off stops and what it doesn't
When command networking is turned off, you can restrict network use by programs run inside the target sandbox. However, Codex client model and authentication requests are separate from command network control. Do not assume that a route by which read code is passed into the model's context is blocked just because command networking is off.
Range reached by command network restriction
Communication by commands, scripts, and their child processes.
Model and authentication, web search, connected apps, MCP, browser and Computer Use, cloud tasks.
To allow networking while limiting destinations, you need to enable the network proxy in addition to domain rules. Writing allowed domains in a profile alone does not take effect.
| Command networking | Proxy | Result |
|---|---|---|
| Off | Either | Command networking is not allowed |
| On | Off | Direct communication is possible, and the profile's domain rules do not apply |
| On | On | Domain rules are applied by the proxy; external destinations are refused unless allowed |
Even an allowed destination can receive secrets. Limiting domains is not the same as inspecting what is sent. When approving execution outside the sandbox, do not assume the current deny settings still protect you; check what the approval widens. OpenAI: network permissions and proxy conditions.
6. Differences in environment variables, OS, and cloud
Secrets are not only in files. If an API key is in the shell, the value may be used from environment variables passed to child processes, even if files are denied. Environment variable inheritance is managed separately with shell_environment_policy.
Automatic exclusion of environment variables: true and false
true (default)Does not automatically exclude variables whose names include KEY, SECRET, or TOKEN
falseApplies that automatic exclusion
ignore_default_excludes. This is a separate control from file deny. Because it excludes by variable name, it is not a mechanism that detects all secrets.Variables with other names, or values that a program fetches from another location, cannot be protected. set is applied after exclusion processing and may restore excluded variables. OpenAI: environment variable inheritance and precedence.
Windows: also check the sandbox mode
Local Permission profiles are described for macOS, Linux, WSL, and native Windows, but the implementations are not the same. Windows has three modes.
Microsoft Execution Containers. This is the recommended mode on supported devices. It needs no administrator-approved setup or dedicated Windows account, and it is available on supported builds of Windows 11 24H2 and 25H2.
An older mode that takes priority when MXC is unavailable. It requires administrator-approved setup.
Communication isolation is weak, and it does not support paths where reads are denied. The secret-file protection settings in this article do not work with it.
Source: OpenAI: Windows sandbox. A policy that cannot be supported is refused at execution. This does not mean you may switch to Full access just because an error appeared. OpenAI: how enforcement works on each OS.
Cloud: do not reuse local settings as they are
Codex Cloud checks the settings of its cloud environment separately. A local profile is not automatically applied to all of cloud, or to dot (ChatGPT's persistent AI agent) on the cloud side. Do not reuse the local setting examples in this article as cloud settings as they are. The differences in execution location are summarized in Codex Remote, Cloud, and PC connection conditions.
7. Steps to verify with dummy files
"We told it not to read," "we saved the setting," and "it was actually refused" are different pieces of evidence. You do not need to have actual secrets test-read. The following are steps for the user or administrator to verify.
- Record the target: Record the Codex version, OS, execution location, and selected permissions. In the CLI, check the working scope with
/statusand the selected state with/permissions. - Check for setting conflicts: Check user settings, trusted project settings, the selected profile, startup flags, and admin constraints. Do not paste entire config files or secret values into the conversation for diagnosis.
- Prepare dummies: In an independent working area that contains no secrets, create files to be allowed and files to be denied. Use the content as a dummy marker.
- Check both allow and deny: Confirm that the allowed target can be read through the same execution path, and that reading the denied target produces an error. Do not treat the fact that Codex voluntarily did not read something as evidence of technical refusal.
- Test placement differences: Check dummies directly under the root, in child folders, with suffixes, and created after startup. Do not grant approval that overrides a refusal. If something is unexpectedly readable, stop using that environment and investigate the cause.
- Check the output path too: Check whether tests or builds write secrets to logs, and whether the same information passes to other MCP servers, browsers, or connected apps.
Since what can be verified varies by CLI version and display, look at the actual display, not only the command name. The official CLI also has a way to check per OS with codex sandbox. However, confirm that settings tested with the helper command match the settings in effect in your usual desktop or IDE session before relying on them. OpenAI: how to test the sandbox.
Content already read cannot be undone by adding a deny later. Separately check past conversations, logs, file retention, and training settings. Do not conclude that information leaked to third parties just because a file was readable. Decide separately what was read, where it went, and whether credentials need action.
Excluding secret files has been requested by users in a public Codex issue. For the current behavior, check the official Permissions docs introduced above.
Premise of this article: Written on October 8, 2026, mainly for commands inside the local sandbox, based on OpenAI's Permissions, Sandbox, approvals and security, and configuration docs. How files created later are handled was rechecked against the official docs on October 19, and the Windows modes on October 16. The sample config has not been applied in an actual environment, so before using it, test refusal with dummies using the steps above.
Related articles: If you want to stop source changes, see How to use Codex and Claude Code in read-only mode. If you want to keep work going within the allowed scope, see Codex Goal mode and reducing approval waits.
FAQ
If it's read-only, won't .env still be sent?
It can be. Read-only only restricts changes. To keep readable .env files out of the model's context, check separately that reads of the target are denied and that the working environment contains no secrets.
Are .gitignore and AGENTS.md enough on their own?
They do not replace technical read denial. Git ignore settings, work instructions, and permissions enforced by the OS are separate mechanisms. Verify with dummies that deny works in your current execution environment.
If I turn off networking, does Codex run entirely on the device?
No. Command network restriction is not a setting that stops communication with the model and authentication. Browser, MCP, connected app, and cloud settings are separate as well.
With this sample config, can secrets be fully protected on Windows?
This sample config alone is not enough. Check beta feature support, the sandbox mode (unelevated does not support read denial), the actual config layers, paths, and the tools you run, and verify refusal with dummies before use.