agent-approvals-security.md +250 −0 added
1# Agent approvals & security
2
3Codex helps protect your code and data and reduces the risk of misuse.
4
5This page covers how to operate Codex safely, including sandboxing, approvals,
6 and network access. If you are looking for Codex Security, the product for
7 scanning connected GitHub repositories, see [Codex Security](https://developers.openai.com/codex/security).
8
9By default, the agent runs with network access turned off. Locally, Codex uses an OS-enforced sandbox that limits what it can touch (typically to the current workspace), plus an approval policy that controls when it must stop and ask you before acting.
10
11## Sandbox and approvals
12
13Codex security controls come from two layers that work together:
14
15- **Sandbox mode**: What Codex can do technically (for example, where it can write and whether it can reach the network) when it executes model-generated commands.
16- **Approval policy**: When Codex must ask you before it executes an action (for example, leaving the sandbox, using the network, or running commands outside a trusted set).
17
18Codex uses different sandbox modes depending on where you run it:
19
20- **Codex cloud**: Runs in isolated OpenAI-managed containers, preventing access to your host system or unrelated data. Uses a two-phase runtime model: setup runs before the agent phase and can access the network to install specified dependencies, then the agent phase runs offline by default unless you enable internet access for that environment. Secrets configured for cloud environments are available only during setup and are removed before the agent phase starts.
21- **Codex CLI / IDE extension**: OS-level mechanisms enforce sandbox policies. Defaults include no network access and write permissions limited to the active workspace. You can configure the sandbox, approval policy, and network settings based on your risk tolerance.
22
23In the `Auto` preset (for example, `--full-auto`), Codex can read files, make edits, and run commands in the working directory automatically.
24
25Codex asks for approval to edit files outside the workspace or to run commands that require network access. If you want to chat or plan without making changes, switch to `read-only` mode with the `/permissions` command.
26
27Codex can also elicit approval for app (connector) tool calls that advertise side effects, even when the action isn't a shell command or file change. Destructive app/MCP tool calls always require approval when the tool advertises a destructive annotation, even if it also advertises other hints (for example, read-only hints).
28
29## Network access [Elevated Risk](https://help.openai.com/articles/20001061)
30
31For Codex cloud, see [agent internet access](https://developers.openai.com/codex/cloud/internet-access) to enable full internet access or a domain allow list.
32
33For the Codex app, CLI, or IDE Extension, the default `workspace-write` sandbox mode keeps network access turned off unless you enable it in your configuration:
34
35```toml
36[sandbox_workspace_write]
37network_access = true
38```
39
40You can also control the [web search tool](https://platform.openai.com/docs/guides/tools-web-search) without granting full network access to spawned commands. Codex defaults to using a web search cache to access results. The cache is an OpenAI-maintained index of web results, so cached mode returns pre-indexed results instead of fetching live pages. This reduces exposure to prompt injection from arbitrary live content, but you should still treat web results as untrusted. If you are using `--yolo` or another [full access sandbox setting](#common-sandbox-and-approval-combinations), web search defaults to live results. Use `--search` or set `web_search = "live"` to allow live browsing, or set it to `"disabled"` to turn the tool off:
41
42```toml
43web_search = "cached" # default
44# web_search = "disabled"
45# web_search = "live" # same as --search
46```
47
48Use caution when enabling network access or web search in Codex. Prompt injection can cause the agent to fetch and follow untrusted instructions.
49
50## Defaults and recommendations
51
52- On launch, Codex detects whether the folder is version-controlled and recommends:
53 - Version-controlled folders: `Auto` (workspace write + on-request approvals)
54 - Non-version-controlled folders: `read-only`
55- Depending on your setup, Codex may also start in `read-only` until you explicitly trust the working directory (for example, via an onboarding prompt or `/permissions`).
56- The workspace includes the current directory and temporary directories like `/tmp`. Use the `/status` command to see which directories are in the workspace.
57- To accept the defaults, run `codex`.
58- You can set these explicitly:
59 - `codex --sandbox workspace-write --ask-for-approval on-request`
60 - `codex --sandbox read-only --ask-for-approval on-request`
61
62### Protected paths in writable roots
63
64In the default `workspace-write` sandbox policy, writable roots still include protected paths:
65
66- `<writable_root>/.git` is protected as read-only whether it appears as a directory or file.
67- If `<writable_root>/.git` is a pointer file (`gitdir: ...`), the resolved Git directory path is also protected as read-only.
68- `<writable_root>/.agents` is protected as read-only when it exists as a directory.
69- `<writable_root>/.codex` is protected as read-only when it exists as a directory.
70- Protection is recursive, so everything under those paths is read-only.
71
72### Run without approval prompts
73
74You can disable approval prompts with `--ask-for-approval never` or `-a never` (shorthand).
75
76This option works with all `--sandbox` modes, so you still control Codex's level of autonomy. Codex makes a best effort within the constraints you set.
77
78If you need Codex to read files, make edits, and run commands with network access without approval prompts, use `--sandbox danger-full-access` (or the `--dangerously-bypass-approvals-and-sandbox` flag). Use caution before doing so.
79
80For a middle ground, `approval_policy = { reject = { ... } }` lets you auto-reject specific approval prompt categories (sandbox escalation, execpolicy-rule prompts, or MCP elicitations) while keeping other prompts interactive.
81
82### Common sandbox and approval combinations
83
84| Intent | Flags | Effect |
85| ----------------------------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
86| Auto (preset) | *no flags needed* or `--full-auto` | Codex can read files, make edits, and run commands in the workspace. Codex requires approval to edit outside the workspace or to access network. |
87| Safe read-only browsing | `--sandbox read-only --ask-for-approval on-request` | Codex can read files and answer questions. Codex requires approval to make edits, run commands, or access network. |
88| Read-only non-interactive (CI) | `--sandbox read-only --ask-for-approval never` | Codex can only read files; never asks for approval. |
89| Automatically edit but ask for approval to run untrusted commands | `--sandbox workspace-write --ask-for-approval untrusted` | Codex can read and edit files but asks for approval before running untrusted commands. |
90| Dangerous full access | `--dangerously-bypass-approvals-and-sandbox` (alias: `--yolo`) | [Elevated Risk](https://help.openai.com/articles/20001061) No sandbox; no approvals *(not recommended)* |
91
92`--full-auto` is a convenience alias for `--sandbox workspace-write --ask-for-approval on-request`.
93
94With `--ask-for-approval untrusted`, Codex runs only known-safe read operations automatically. Commands that can mutate state or trigger external execution paths (for example, destructive Git operations or Git output/config-override flags) require approval.
95
96#### Configuration in `config.toml`
97
98For the broader configuration workflow, see [Config basics](https://developers.openai.com/codex/config-basic), [Advanced Config](https://developers.openai.com/codex/config-advanced#approval-policies-and-sandbox-modes), and the [Configuration Reference](https://developers.openai.com/codex/config-reference).
99
100```toml
101# Always ask for approval mode
102approval_policy = "untrusted"
103sandbox_mode = "read-only"
104allow_login_shell = false # optional hardening: disallow login shells for shell-based tools
105
106# Optional: Allow network in workspace-write mode
107[sandbox_workspace_write]
108network_access = true
109
110# Optional: granular approval prompt auto-rejection
111# approval_policy = { reject = { sandbox_approval = true, rules = false, mcp_elicitations = false } }
112```
113
114You can also save presets as profiles, then select them with `codex --profile <name>`:
115
116```toml
117[profiles.full_auto]
118approval_policy = "on-request"
119sandbox_mode = "workspace-write"
120
121[profiles.readonly_quiet]
122approval_policy = "never"
123sandbox_mode = "read-only"
124```
125
126### Test the sandbox locally
127
128To see what happens when a command runs under the Codex sandbox, use these Codex CLI commands:
129
130```bash
131# macOS
132codex sandbox macos [--full-auto] [--log-denials] [COMMAND]...
133# Linux
134codex sandbox linux [--full-auto] [COMMAND]...
135```
136
137The `sandbox` command is also available as `codex debug`, and the platform helpers have aliases (for example `codex sandbox seatbelt` and `codex sandbox landlock`).
138
139## OS-level sandbox
140
141Codex enforces the sandbox differently depending on your OS:
142
143- **macOS** uses Seatbelt policies and runs commands using `sandbox-exec` with a profile (`-p`) that corresponds to the `--sandbox` mode you selected. When restricted read access enables platform defaults, Codex appends a curated macOS platform policy (instead of broadly allowing `/System`) to preserve common tool compatibility.
144- **Linux** uses `Landlock` plus `seccomp` by default. You can opt into the alternative Linux sandbox pipeline with `features.use_linux_sandbox_bwrap = true` (or `-c use_linux_sandbox_bwrap=true`). In managed proxy mode, the bwrap pipeline routes egress through a proxy-only bridge and fails closed if it cannot build valid loopback proxy routes; landlock-only flows do not use that bridge behavior.
145- **Windows** uses the Linux sandbox implementation when running in [Windows Subsystem for Linux (WSL)](https://developers.openai.com/codex/windows#windows-subsystem-for-linux). When running natively on Windows, Codex uses a [Windows sandbox](https://developers.openai.com/codex/windows#windows-sandbox) implementation.
146
147If you use the Codex IDE extension on Windows, it supports WSL directly. Set the following in your VS Code settings to keep the agent inside WSL whenever it’s available:
148
149```json
150{
151 "chatgpt.runCodexInWindowsSubsystemForLinux": true
152}
153```
154
155This ensures the IDE extension inherits Linux sandbox semantics for commands, approvals, and filesystem access even when the host OS is Windows. Learn more in the [Windows setup guide](https://developers.openai.com/codex/windows).
156
157When running natively on Windows, configure the native sandbox mode in `config.toml`:
158
159```toml
160[windows]
161sandbox = "unelevated" # or "elevated"
162```
163
164See the [Windows setup guide](https://developers.openai.com/codex/windows#windows-sandbox) for details.
165
166When you run Linux in a containerized environment such as Docker, the sandbox may not work if the host or container configuration doesn’t support the required `Landlock` and `seccomp` features.
167
168In that case, configure your Docker container to provide the isolation you need, then run `codex` with `--sandbox danger-full-access` (or the `--dangerously-bypass-approvals-and-sandbox` flag) inside the container.
169
170## Version control
171
172Codex works best with a version control workflow:
173
174- Work on a feature branch and keep `git status` clean before delegating. This keeps Codex patches easier to isolate and revert.
175- Prefer patch-based workflows (for example, `git diff`/`git apply`) over editing tracked files directly. Commit frequently so you can roll back in small increments.
176- Treat Codex suggestions like any other PR: run targeted verification, review diffs, and document decisions in commit messages for auditing.
177
178## Monitoring and telemetry
179
180Codex supports opt-in monitoring via OpenTelemetry (OTel) to help teams audit usage, investigate issues, and meet compliance requirements without weakening local security defaults. Telemetry is off by default; enable it explicitly in your configuration.
181
182### Overview
183
184- Codex turns off OTel export by default to keep local runs self-contained.
185- When enabled, Codex emits structured log events covering conversations, API requests, SSE/WebSocket stream activity, user prompts (redacted by default), tool approval decisions, and tool results.
186- Codex tags exported events with `service.name` (originator), CLI version, and an environment label to separate dev/staging/prod traffic.
187
188### Enable OTel (opt-in)
189
190Add an `[otel]` block to your Codex configuration (typically `~/.codex/config.toml`), choosing an exporter and whether to log prompt text.
191
192```toml
193[otel]
194environment = "staging" # dev | staging | prod
195exporter = "none" # none | otlp-http | otlp-grpc
196log_user_prompt = false # redact prompt text unless policy allows
197```
198
199- `exporter = "none"` leaves instrumentation active but doesn't send data anywhere.
200- To send events to your own collector, pick one of:
201
202```toml
203[otel]
204exporter = { otlp-http = {
205 endpoint = "https://otel.example.com/v1/logs",
206 protocol = "binary",
207 headers = { "x-otlp-api-key" = "${OTLP_TOKEN}" }
208}}
209```
210
211```toml
212[otel]
213exporter = { otlp-grpc = {
214 endpoint = "https://otel.example.com:4317",
215 headers = { "x-otlp-meta" = "abc123" }
216}}
217```
218
219Codex batches events and flushes them on shutdown. Codex exports only telemetry produced by its OTel module.
220
221### Event categories
222
223Representative event types include:
224
225- `codex.conversation_starts` (model, reasoning settings, sandbox/approval policy)
226- `codex.api_request` (attempt, status/success, duration, and error details)
227- `codex.sse_event` (stream event kind, success/failure, duration, plus token counts on `response.completed`)
228- `codex.websocket_request` and `codex.websocket_event` (request duration plus per-message kind/success/error)
229- `codex.user_prompt` (length; content redacted unless explicitly enabled)
230- `codex.tool_decision` (approved/denied, source: configuration vs. user)
231- `codex.tool_result` (duration, success, output snippet)
232
233Associated OTel metrics (counter plus duration histogram pairs) include `codex.api_request`, `codex.sse_event`, `codex.websocket.request`, `codex.websocket.event`, and `codex.tool.call` (with corresponding `.duration_ms` instruments).
234
235For the full event catalog and configuration reference, see the [Codex configuration documentation on GitHub](https://github.com/openai/codex/blob/main/docs/config.md#otel).
236
237### Security and privacy guidance
238
239- Keep `log_user_prompt = false` unless policy explicitly permits storing prompt contents. Prompts can include source code and sensitive data.
240- Route telemetry only to collectors you control; apply retention limits and access controls aligned with your compliance requirements.
241- Treat tool arguments and outputs as sensitive. Favor redaction at the collector or SIEM when possible.
242- Review local data retention settings (for example, `history.persistence` / `history.max_bytes`) if you don't want Codex to save session transcripts under `CODEX_HOME`. See [Advanced Config](https://developers.openai.com/codex/config-advanced#history-persistence) and [Configuration Reference](https://developers.openai.com/codex/config-reference).
243- If you run the CLI with network access turned off, OTel export can't reach your collector. To export, allow network access in `workspace-write` mode for the OTel endpoint, or export from Codex cloud with the collector domain on your approved list.
244- Review events periodically for approval/sandbox changes and unexpected tool executions.
245
246OTel is optional and designed to complement, not replace, the sandbox and approval protections described above.
247
248## Managed configuration
249
250Enterprise admins can configure Codex security settings for their workspace in [Managed configuration](https://developers.openai.com/codex/enterprise/managed-configuration). See that page for setup and policy details.