SECURITY

A coding agent security checklist for Claude Code and Codex

A concrete security checklist for running Claude Code or Codex on your own machine, covering permissions, secrets, sandboxing, network, MCP and git.

Short answer

To run Claude Code or Codex safely on your machine, keep permission prompts on for risky actions, deny access to secrets such as .env files, turn on the sandbox, limit network access, treat files and web pages as untrusted input, vet every MCP server, and review the git diff before anything is pushed.

A coding agent runs commands with your user account, so its security is mostly your configuration. Claude Code and Codex both ship sensible defaults, but the defaults assume you read what you approve, and they do not know which files on your machine are sensitive.

This checklist goes through the controls that matter, in the order you would set them up. Each item says what to do and why, with the exact settings from the official docs.

What is the actual risk?

The risk is an agent doing something harmful with your permissions: deleting work, reading credentials, or sending data somewhere it should not. That can come from a plain mistake, or from instructions hidden in content the agent reads, which is called prompt injection.

OWASP lists prompt injection first in its Top 10 for LLM applications and separates direct injection (in the user's prompt) from indirect injection, which arrives through external sources such as websites or files. A coding agent reads a lot of external content: READMEs, issues, dependency code, web pages.

Simon Willison's lethal trifecta is a useful way to think about it. An agent becomes dangerous when it combines access to private data, exposure to untrusted content, and the ability to communicate externally. Most items below remove or restrict one of those three.

1. Know your permission mode

Check which mode your agent starts in, and keep risky actions behind a prompt. This is the first control because everything else depends on it.

In Claude Code, recent versions start interactive terminal sessions in auto mode, where a separate classifier model reviews actions and blocks the ones it judges unsafe. The permission modes docs say plainly that auto mode reduces prompts "but does not guarantee safety". Manual mode (default) prompts before most edits, shell commands and network requests. Press Shift+Tab to cycle modes and read the status bar.

In Codex, the sandbox mode and the approval policy work together. The default Auto preset is --sandbox workspace-write --ask-for-approval on-request, which lets Codex edit and run commands in the workspace and asks before actions such as editing outside it or using the network, according to the Codex approvals and security page.

  • Do not use bypassPermissions (--dangerously-skip-permissions) or Codex's --dangerously-bypass-approvals-and-sandbox (--yolo) on your main machine.
  • Use plan mode in Claude Code, or read-only in Codex, when you only want analysis.

The guides on Claude Code permission modes and Codex approval modes go deeper.

2. Deny access to secrets

Add deny rules for every file that holds credentials. A deny rule blocks in every Claude Code mode, including bypassPermissions.

This example from the Claude Code settings reference denies reads of .env files, a secrets folder and a credentials file, and blocks curl:

{
  "permissions": {
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(./secrets/**)",
      "Read(./config/credentials.json)",
      "Bash(curl *)"
    ]
  }
}

Know the limits. Read deny rules apply to Claude's file tools and to Bash commands Claude Code can analyze, such as cat or head. They do not stop a Python or Node script that opens the file itself, and a Bash rule like Bash(curl *) does not stop /usr/bin/curl or sh -c 'curl ...'. The permissions docs are explicit that a Bash rule is not a security boundary around a program. For enforcement that does not depend on the command text, use the sandbox (next item).

In Codex, .git, .codex, .agents and .aws directories inside writable roots are protected as read-only. For environment variables, set shell_environment_policy. By default ignore_default_excludes is true, so Codex does not strip variables containing KEY, SECRET or TOKEN unless you set it to false:

[shell_environment_policy]
inherit = "core"
ignore_default_excludes = false

[shell_environment_policy.filters]
"AWS_*" = "exclude"

Better still, keep long-lived secrets out of the project folder and out of your shell environment while agents run.

3. Turn on the sandbox

Enable OS-level sandboxing so a command cannot exceed its boundary even if it was approved. Permission rules are checked before a tool runs; the sandbox is enforced by the operating system on the running process.

In Claude Code, the Bash sandbox is off by default. Turn it on with /sandbox or in settings. On macOS it uses Seatbelt. By default, sandboxed commands can write only to the working directory, a temp directory and added directories, but they can read most of the machine, including ~/.ssh and ~/.aws/credentials, so add read restrictions:

{
  "sandbox": {
    "enabled": true,
    "failIfUnavailable": true,
    "allowUnsandboxedCommands": false,
    "filesystem": {
      "denyRead": ["~/.ssh", "~/.aws"]
    }
  }
}

allowUnsandboxedCommands: false turns off the retry outside the sandbox when a command fails. Note that only shell commands are sandboxed: Claude's file tools, hooks and local MCP servers run with your full access.

Codex sandboxes by default (workspace-write), also with Seatbelt on macOS. Never use danger-full-access outside a disposable environment.

For the strongest isolation, run the whole agent in a dev container or a VM. See agent sandbox for the concepts.

4. Restrict network access

Keep outbound network access off or allowlisted. Network access is the "externally communicate" leg of the trifecta.

  • Codex's workspace-write sandbox has network off unless you set network_access = true under [sandbox_workspace_write].
  • Claude Code's sandbox routes traffic through a proxy that checks each host against network.allowedDomains, which starts empty. Add only what your work needs, such as your package registry.
  • In Claude Code Manual mode, curl and wget prompt by default. Approve them one at a time unless you trust the destination.
  • Use WebFetch(domain:...) rules rather than allowing all fetches.

5. Treat files and web pages as untrusted input

Assume any content the agent reads might contain instructions. That includes READMEs from cloned repos, issue text, error messages, dependency source and web pages.

Claude Code's security page recommends reviewing suggested commands before approval, avoiding piping untrusted content directly to Claude, and using VMs when interacting with external web services. It also notes that for most WebFetch calls a separate model reads the page and Claude receives a summary rather than the raw page, which reduces but does not remove the risk. Codex's docs say prompt injection "can cause the agent to fetch and follow untrusted instructions" and that web results should be treated as untrusted.

In practice: be most careful right after the agent has read something from outside your project. That is when an unexpected curl, a write to a dotfile or a push deserves a second look.

6. Vet every MCP server

Install only MCP servers you wrote or that come from providers you trust. An MCP server adds tools, and local servers run with your full user access, outside the sandbox.

  • Review .mcp.json in any repo you clone. Claude Code asks for approval before using servers from a project's .mcp.json, but that file does not show every server a session can load, since user-level servers and plugins add more.
  • Disable servers you are not using (/mcp in Claude Code).
  • Prefer read-only scopes and tokens for MCP integrations.
  • Be wary of combining a server that reads private data with one that reads public content and one that can send messages. That is the trifecta again.

Anthropic states that it does not security-audit or manage MCP servers, even those listed in its directory.

7. Keep git hygiene

Make every agent change reviewable and reversible. Git is your undo button, so protect it.

  • Start each task from a clean working tree, and commit or stash before the agent runs.
  • Work on a branch or in a git worktree, never directly on main.
  • Put an ask rule on pushes, for example Bash(git push *) in ask, so a push always needs your click.
  • Use branch protection on the remote so a pushed branch cannot skip review.
  • Keep secrets in .gitignore and check git status before every commit.

Claude Code treats .git, .husky, shell startup files and .mcp.json as protected paths that prompt for writes in Manual mode, and Codex keeps .git read-only inside writable roots.

8. Read commands before you allow them

Read the whole command, not the first word. Most bad approvals happen because the prompt looked familiar.

  • Check for chained commands (&&, ;, |), redirections and subshells.
  • Check the paths: anything outside the project, in your home folder or in a dotfile deserves attention.
  • Check for network destinations you do not recognize.
  • When in doubt, deny and ask the agent to explain.

Allowlist only narrow, repetitive, harmless commands, such as Bash(npm run test *). Place the * after the subcommand: Bash(git log *) allows only git log, while Bash(git *) allows every git command. The guide on allowing commands in Claude Code shows good patterns, and human in the loop for coding agents explains which actions deserve a click.

The checklist in one table

AreaClaude CodeCodex
ModeKnow if you are in auto or Manual; avoid bypassPermissionsAuto preset; avoid --yolo
SecretsRead(./.env) deny rulesshell_environment_policy, protected dirs
Sandbox/sandbox, failIfUnavailable, denyReadworkspace-write (default)
NetworkallowedDomains, prompt on curlnetwork_access off by default
Untrusted inputReview after web readsTreat web results as untrusted
MCPReview .mcp.json, /mcpTrusted servers only
GitAsk rule on git push, branchesBranches, .git protected
ReviewRead the full commandRead the full command

Keeping approvals fast without lowering the bar

The hardest part of this checklist is item 8, because careful review is slow and slow review becomes rubber-stamping. Allowbar is a Mac menu bar app for Claude Code and Codex that shows each permission request in a panel at the top of the screen, with the project, the tool and the exact command, so you can read it properly from wherever you are and answer Allow, Block, or Terminal.

Allowbar never approves anything on its own. It has no auto approval and no rules that approve for you; if you do not answer, the question goes back to the terminal, and a missing answer is never treated as approval. It adds entries to the agents' own hook files, leaves your other settings untouched, and sends nothing to a cloud service. It does not replace the sandbox or deny rules above, it is Mac only, and it supports Claude Code and Codex. Allowbar is in private beta. Join the waitlist; the launch price is $9.99 instead of $29.90.

Sources:

Frequently asked questions

Is Claude Code safe to run on my main machine?

It can be, with a sensible setup: risky actions behind a prompt or the auto mode classifier, deny rules for secrets, the sandbox turned on, and a diff review before you push. Avoid bypassPermissions on a machine with your credentials and personal files.

How do I stop Claude Code from reading my .env file?

Add Read(./.env) and Read(./.env.*) to permissions.deny in your settings. This blocks Claude's file tools and the shell commands Claude Code recognizes. To stop scripts from reading it too, enable the sandbox and add the path to sandbox.filesystem.denyRead.

Does the Codex sandbox block network access?

In the default workspace-write mode, network access is off unless you set network_access = true under [sandbox_workspace_write]. With danger-full-access or --yolo, there is no sandbox at all.

Can a README or web page hijack my coding agent?

It can try. Instructions hidden in files or pages the agent reads are indirect prompt injection. Both Claude Code and Codex add protections, but neither claims full immunity, so review commands that follow external reads and limit network access.

Are MCP servers safe?

An MCP server is code you run with your own access, so it is as safe as its author and your configuration. Use servers you trust, review project .mcp.json files, and disable the ones you do not need.

ALLOWBAR FOR MAC

Answer your agents from the menu bar.

Permission requests from Claude Code and Codex slide down from the top of your screen. Allow, Block or send back to the terminal. Allowbar never approves anything on its own.

Launch price $9.99 instead of $29.90, one-time purchase, lifetime license.