agent-approvals-security.md +254 −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
11For a high-level explanation of how sandboxing works across the Codex app, IDE
12extension, and CLI, see [Sandboxing](https://developers.openai.com/codex/concepts/sandboxing).
13For a broader enterprise security overview, see the [Codex security white paper](https://trust.openai.com/?itemUid=382f924d-54f3-43a8-a9df-c39e6c959958&source=click).
14
15## Sandbox and approvals
16
17Codex security controls come from two layers that work together:
18
19- **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.
20- **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).
21
22Codex uses different sandbox modes depending on where you run it:
23
24- **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.
25- **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.
26
27In the `Auto` preset (for example, `--full-auto`), Codex can read files, make edits, and run commands in the working directory automatically.
28
29Codex 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.
30
31Codex 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).
32
33## Network access [Elevated Risk](https://help.openai.com/articles/20001061)
34
35For Codex cloud, see [agent internet access](https://developers.openai.com/codex/cloud/internet-access) to enable full internet access or a domain allow list.
36
37For 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:
38
39```toml
40[sandbox_workspace_write]
41network_access = true
42```
43
44You 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:
45
46```toml
47web_search = "cached" # default
48# web_search = "disabled"
49# web_search = "live" # same as --search
50```
51
52Use caution when enabling network access or web search in Codex. Prompt injection can cause the agent to fetch and follow untrusted instructions.
53
54## Defaults and recommendations
55
56- On launch, Codex detects whether the folder is version-controlled and recommends:
57 - Version-controlled folders: `Auto` (workspace write + on-request approvals)
58 - Non-version-controlled folders: `read-only`
59- 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`).
60- The workspace includes the current directory and temporary directories like `/tmp`. Use the `/status` command to see which directories are in the workspace.
61- To accept the defaults, run `codex`.
62- You can set these explicitly:
63 - `codex --sandbox workspace-write --ask-for-approval on-request`
64 - `codex --sandbox read-only --ask-for-approval on-request`
65
66### Protected paths in writable roots
67
68In the default `workspace-write` sandbox policy, writable roots still include protected paths:
69
70- `<writable_root>/.git` is protected as read-only whether it appears as a directory or file.
71- If `<writable_root>/.git` is a pointer file (`gitdir: ...`), the resolved Git directory path is also protected as read-only.
72- `<writable_root>/.agents` is protected as read-only when it exists as a directory.
73- `<writable_root>/.codex` is protected as read-only when it exists as a directory.
74- Protection is recursive, so everything under those paths is read-only.
75
76### Run without approval prompts
77
78You can disable approval prompts with `--ask-for-approval never` or `-a never` (shorthand).
79
80This 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.
81
82If 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.
83
84For 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.
85
86### Common sandbox and approval combinations
87
88| Intent | Flags | Effect |
89| ----------------------------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
90| 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. |
91| 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. |
92| Read-only non-interactive (CI) | `--sandbox read-only --ask-for-approval never` | Codex can only read files; never asks for approval. |
93| 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. |
94| Dangerous full access | `--dangerously-bypass-approvals-and-sandbox` (alias: `--yolo`) | [Elevated Risk](https://help.openai.com/articles/20001061) No sandbox; no approvals *(not recommended)* |
95
96`--full-auto` is a convenience alias for `--sandbox workspace-write --ask-for-approval on-request`.
97
98With `--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.
99
100#### Configuration in `config.toml`
101
102For 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).
103
104```toml
105# Always ask for approval mode
106approval_policy = "untrusted"
107sandbox_mode = "read-only"
108allow_login_shell = false # optional hardening: disallow login shells for shell-based tools
109
110# Optional: Allow network in workspace-write mode
111[sandbox_workspace_write]
112network_access = true
113
114# Optional: granular approval prompt auto-rejection
115# approval_policy = { reject = { sandbox_approval = true, rules = false, mcp_elicitations = false } }
116```
117
118You can also save presets as profiles, then select them with `codex --profile <name>`:
119
120```toml
121[profiles.full_auto]
122approval_policy = "on-request"
123sandbox_mode = "workspace-write"
124
125[profiles.readonly_quiet]
126approval_policy = "never"
127sandbox_mode = "read-only"
128```
129
130### Test the sandbox locally
131
132To see what happens when a command runs under the Codex sandbox, use these Codex CLI commands:
133
134```bash
135# macOS
136codex sandbox macos [--full-auto] [--log-denials] [COMMAND]...
137# Linux
138codex sandbox linux [--full-auto] [COMMAND]...
139```
140
141The `sandbox` command is also available as `codex debug`, and the platform helpers have aliases (for example `codex sandbox seatbelt` and `codex sandbox landlock`).
142
143## OS-level sandbox
144
145Codex enforces the sandbox differently depending on your OS:
146
147- **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.
148- **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.
149- **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.
150
151If 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:
152
153```json
154{
155 "chatgpt.runCodexInWindowsSubsystemForLinux": true
156}
157```
158
159This 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).
160
161When running natively on Windows, configure the native sandbox mode in `config.toml`:
162
163```toml
164[windows]
165sandbox = "unelevated" # or "elevated"
166```
167
168See the [Windows setup guide](https://developers.openai.com/codex/windows#windows-sandbox) for details.
169
170When 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.
171
172In 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.
173
174## Version control
175
176Codex works best with a version control workflow:
177
178- Work on a feature branch and keep `git status` clean before delegating. This keeps Codex patches easier to isolate and revert.
179- 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.
180- Treat Codex suggestions like any other PR: run targeted verification, review diffs, and document decisions in commit messages for auditing.
181
182## Monitoring and telemetry
183
184Codex 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.
185
186### Overview
187
188- Codex turns off OTel export by default to keep local runs self-contained.
189- 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.
190- Codex tags exported events with `service.name` (originator), CLI version, and an environment label to separate dev/staging/prod traffic.
191
192### Enable OTel (opt-in)
193
194Add an `[otel]` block to your Codex configuration (typically `~/.codex/config.toml`), choosing an exporter and whether to log prompt text.
195
196```toml
197[otel]
198environment = "staging" # dev | staging | prod
199exporter = "none" # none | otlp-http | otlp-grpc
200log_user_prompt = false # redact prompt text unless policy allows
201```
202
203- `exporter = "none"` leaves instrumentation active but doesn't send data anywhere.
204- To send events to your own collector, pick one of:
205
206```toml
207[otel]
208exporter = { otlp-http = {
209 endpoint = "https://otel.example.com/v1/logs",
210 protocol = "binary",
211 headers = { "x-otlp-api-key" = "${OTLP_TOKEN}" }
212}}
213```
214
215```toml
216[otel]
217exporter = { otlp-grpc = {
218 endpoint = "https://otel.example.com:4317",
219 headers = { "x-otlp-meta" = "abc123" }
220}}
221```
222
223Codex batches events and flushes them on shutdown. Codex exports only telemetry produced by its OTel module.
224
225### Event categories
226
227Representative event types include:
228
229- `codex.conversation_starts` (model, reasoning settings, sandbox/approval policy)
230- `codex.api_request` (attempt, status/success, duration, and error details)
231- `codex.sse_event` (stream event kind, success/failure, duration, plus token counts on `response.completed`)
232- `codex.websocket_request` and `codex.websocket_event` (request duration plus per-message kind/success/error)
233- `codex.user_prompt` (length; content redacted unless explicitly enabled)
234- `codex.tool_decision` (approved/denied, source: configuration vs. user)
235- `codex.tool_result` (duration, success, output snippet)
236
237Associated 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).
238
239For 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).
240
241### Security and privacy guidance
242
243- Keep `log_user_prompt = false` unless policy explicitly permits storing prompt contents. Prompts can include source code and sensitive data.
244- Route telemetry only to collectors you control; apply retention limits and access controls aligned with your compliance requirements.
245- Treat tool arguments and outputs as sensitive. Favor redaction at the collector or SIEM when possible.
246- 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).
247- 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.
248- Review events periodically for approval/sandbox changes and unexpected tool executions.
249
250OTel is optional and designed to complement, not replace, the sandbox and approval protections described above.
251
252## Managed configuration
253
254Enterprise 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.