Padlock on a laptop keyboard, illustrating AI coding agent permissions
Geeky

AI Coding Agent Permissions: How to Lock Them Down

I once asked Codex to add a new feature to one of my projects and left it to do its thing. Along the way, it decided to change the database schema, and some tables were rebuilt by dropping and recreating them. All the data in those tables was gone.

It was a local database, so nothing important was lost. It still taught me something about AI coding agent permissions that I’d only half understood: the agent will do whatever its permissions allow, whether or not that’s what you asked for.

That wasn’t my only warning. On another occasion, I asked Gemini 2.5 Flash a simple question about a repo, and it tried to push changes to production. The only thing in the way was that I was in a normal chat mode, so it had to ask for my permission first. In a more autonomous mode, nothing would have stopped it.

Neither of these was a hack. Both were helpful agents doing more than I asked, with access nobody had taken away from them. This post shows you how to take that access away in the three agents I use: Claude Code, OpenAI’s Codex CLI, and Google Antigravity.

Why AI coding agent permissions matter more than the model

Agents usually go wrong in one of three ways.

  • They misread the task. The best-known example is the Antigravity user who asked the agent to clear a project cache and lost his entire D: drive instead. He was running Turbo mode, which executes commands without asking, as The Register reported.
  • They overreach. You ask for a feature and the agent decides the schema needs fixing. You ask a question and it decides to deploy. This is my Codex and Gemini problem.
  • They follow someone else’s instructions. An agent reads READMEs, issue comments, web pages, and dependency docs. Any of those can contain text written to steer the agent, which is called prompt injection. The agent can’t reliably tell your instructions from a stranger’s.

You can’t fix any of these by picking a smarter model. You fix them by limiting what any model can do on your machine. The security community has caught up with this too: OWASP published a dedicated Top 10 for Agentic Applications in December 2025. My practical reading of it is simple: give the agent only the access the task needs, and nothing it might find useful later.

Approval rules and sandboxes are two different locks

Toy sandbox on a desk as a metaphor for an AI coding agent sandbox

Every serious coding agent now has two separate controls, and mixing them up gives you a false sense of safety.

Approvals decide when the agent stops and asks you. They work by matching what the agent is about to do against rules you write, like “ask before git push” or “never read .env.”

The sandbox is an operating-system-level wall around the commands the agent runs. A command inside it physically can’t write outside your project or reach the internet, whatever the agent intended.

Approval rules are useful, but they match text. Anthropic’s own Claude Code permissions docs say plainly that a deny rule for curl doesn’t stop /usr/bin/curl or sh -c 'curl ...'. A deny rule on reading .env also doesn’t stop a Python script the agent writes that opens .env on its own. The sandbox does.

My rule of thumb: approvals catch mistakes, the sandbox contains them. You want both.

Claude CodeCodex CLIAntigravity
Asks before commands by defaultYes (Manual mode)Only to leave the sandboxOnly outside the sandbox (Default preset)
Sandbox on by defaultNo, you enable itYesYes (Default preset)
Network in sandboxAllowlist, empty by defaultOff by defaultOff by default
Can block secret filesDeny rules + sandbox denyReadPermission profiles (beta)read_file deny rules
Full-auto escape hatchbypassPermissions--yoloTurbo preset

Claude Code: modes, deny rules, and the sandbox

Claude Code is the most configurable of the three, but its sandbox stays off until you turn it on.

Pick the right permission mode

Claude Code has several modes. The ones that matter here:

  • Manual (default): asks the first time it uses each tool. Start here.
  • acceptEdits: edits files and runs basic file commands without asking.
  • plan: reads and explores but doesn’t edit your source files. Use it when you only have a question.
  • auto: a background classifier reviews actions instead of you.
  • bypassPermissions: skips prompts. Anthropic’s docs say to use it only in isolated containers or VMs.

You can block the risky modes outright by setting permissions.disableBypassPermissionsMode (and disableAutoMode, if you want) to "disable".

Write deny rules for secrets and dangerous commands

Rules go in ~/.claude/settings.json (for every project) or .claude/settings.json (for one repo). They’re checked in a fixed order, deny then ask then allow, and a deny always wins. Here’s a starting point:

{
  "permissions": {
    "deny": [
      "Read(**/.env*)",
      "Read(**/*.pem)",
      "Read(**/*.key)",
      "Read(~/.ssh/**)",
      "Read(~/.aws/**)",
      "Bash(terraform *)",
      "Bash(aws *)"
    ],
    "ask": [
      "Bash(git push *)",
      "Bash(npm publish *)"
    ],
    "disableBypassPermissionsMode": "disable"
  }
}

Run /permissions inside Claude Code to see every active rule and which file it came from.

One thing that trips people up: putting “never push to main” in CLAUDE.md is a request, not a lock. The docs say instructions there shape what Claude tries but don’t change what Claude Code allows.

Turn on the sandbox

The sandbox is off by default. Run /sandbox, or add a sandbox block to your settings:

{
  "sandbox": {
    "enabled": true,
    "allowUnsandboxedCommands": false,
    "failIfUnavailable": true,
    "filesystem": {
      "denyRead": ["~/.ssh/**", "~/.aws/**", "~/.gnupg/**", "~/.config/gh/**"]
    },
    "network": {
      "allowedDomains": ["github.com", "registry.npmjs.org"]
    }
  }
}

The denyRead line matters more than it looks. According to the Claude Code sandboxing docs, the default sandbox limits writes to your project but still lets commands read most of your machine, including ~/.ssh. allowUnsandboxedCommands: false stops Claude from retrying a blocked command outside the sandbox. failIfUnavailable makes Claude Code refuse to start instead of quietly running without the sandbox.

Platform support:

  • macOS: works out of the box (Apple’s Seatbelt).
  • Linux and WSL2: install bubblewrap and socat first (sudo dnf install bubblewrap socat on Fedora, sudo apt-get install bubblewrap socat on Ubuntu).
  • Native Windows: commands run unsandboxed. If you’re on Windows, run Claude Code inside WSL2.

What this looks like at work

At work, my Claude Code is a good reference for what “locked down” means in practice:

  • Reads of .env*, .pem, .key, and id_rsa* files, plus secrets/ and credentials/ folders, are denied, and so are edits to .env files, secrets/, and ~/.ssh.
  • The sandbox is on, and it can’t read or write ~/.ssh, ~/.aws, ~/.gnupg, or the GitHub CLI’s config folder.
  • brew, terraform, and aws commands are denied entirely.
  • Bypass mode is disabled.

Codex CLI: sandbox modes, approvals, and profiles

Codex starts out stricter than Claude Code because its sandbox is on by default. OpenAI’s Codex security docs describe two settings that work together.

Sandbox modes:

  • read-only: can’t change anything. Default for folders that aren’t under version control.
  • workspace-write: can edit the project and run commands there, with no network. Default for git repos, paired with the on-request approval policy (OpenAI calls this pair “Auto”).
  • danger-full-access: no sandbox.

Approval policies: on-request asks when a command needs to leave the sandbox or use the network. never doesn’t ask. granular lets you choose which kinds of prompts stay on. If an old config still says untrusted, remove it. That policy is retired and can stop Codex from starting.

Even in workspace-write, Codex keeps .git, .agents, .codex, and .aws read-only. That’s a nice safety net for your history.

To block secrets, use a permission profile in ~/.codex/config.toml. The permissions docs mark profiles as beta, but this pattern comes straight from them:

approval_policy = "on-request"
default_permissions = "locked-down"

[permissions.locked-down]

description = “Workspace edits, no secrets, no network” extends = “:workspace”

[permissions.locked-down.filesystem.”:workspace_roots”]

“**/*.env” = “deny”

Two warnings. First, if any loaded config sets the older sandbox_mode key, or you pass --sandbox, Codex uses that instead of your profile. Remove the old key. Second, --yolo (long form --dangerously-bypass-approvals-and-sandbox) removes both the sandbox and the approvals. Keep it for throwaway VMs.

Run /permissions mid-session to switch modes, for example to read-only when you only want to ask questions.

Codex sandboxes on all three platforms: Seatbelt on macOS, bubblewrap plus seccomp on Linux, a native sandbox on Windows, and the Linux sandbox inside WSL2.

One lesson from my schema incident: a sandbox protects files and network access. It doesn’t make a destructive migration safe if the agent can run it against a database it’s allowed to reach. That takes the habits further down.

Google Antigravity: presets and rules

Antigravity replaced its old settings with permission presets. The Antigravity permissions docs list four, under Settings > General > Global Permissions:

  • Request Review: no sandbox, asks before every terminal command, limits files to the workspace.
  • Default: sandbox on, runs commands inside it without asking, and asks for anything that needs network or files outside the workspace and temp folders.
  • Auto: sandbox on. Commands that need to leave the sandbox are judged automatically: safe, reversible ones run and risky ones ask.
  • Turbo: no sandbox, full filesystem access, no prompts. This is the mode from the D: drive story.

Default is a sensible place to stay. Projects can override the global preset under Settings > Projects, so you can keep a riskier repo on Request Review.

On top of any preset you can add allow, ask, and deny rules in the form action(target). Deny beats ask, and ask beats allow:

Deny:   command(rm -rf)
Deny:   read_file(/home/you/.ssh)
Ask:    command(git push)
Allow:  command(npm run (build|lint|test))

If you use the Antigravity CLI, the same rules go in ~/.gemini/antigravity-cli/settings.json under permissions, or you can manage them with /permissions.

Two caveats. The docs say business and enterprise accounts use the older settings (terminal auto-execution and allow/deny lists) instead of presets. Also, the sandbox-backed Auto preset needs the sandbox to be available. If it isn’t, Default falls back to Request Review.

Habits that save you when the settings don’t

Backup drive and notebook, habits that back up AI coding agent permissions

Settings reduce risk. They don’t remove it. These habits cover what’s left:

  • Commit before you hand off. A clean working tree means git diff shows everything the agent touched, and git restore . or git reset --hard undoes it.
  • Work on a branch. Agents should never be one command away from your main branch.
  • Give agents disposable databases. Use a local container or a seeded copy. Treat any schema change the agent proposes like a pull request and read the migration before it runs.
  • Keep production credentials off your dev machine. The agent can’t leak or misuse a key it can’t reach. Use short-lived tokens where you can.
  • Match the mode to the question. Plan or read-only mode for questions, normal mode for edits, full-auto only inside a container or VM.
  • Review the work, not just the result. Tests passing doesn’t mean nothing else changed.

Pro Tip: Before trusting any deny rule, test it. Ask the agent to cat your .env or run a blocked command, and confirm it refuses. A rule with the wrong path pattern simply won’t match, and you won’t know until you check.

FAQ

What’s the safest permission mode for an AI coding agent?

A sandboxed mode that asks before leaving the sandbox: Claude Code in Manual mode with the sandbox on, Codex’s default Auto (workspace-write plus on-request), or Antigravity’s Default preset. Read-only or plan mode is safer still when you’re only asking questions.

Does blocking .env in the rules fully protect my secrets?

No. Rule-based blocks can miss indirect reads, like a script that opens the file itself. Pair them with sandbox-level read blocks and keep high-value credentials off the machine entirely.

Is YOLO or Turbo mode ever okay?

Inside a disposable container or VM with no credentials and a fresh copy of the code, yes. On your daily machine, no. That’s exactly how the D: drive incident happened.

Do these settings slow the agent down?

Somewhat, at first. Expect more prompts until you add allow rules for the safe commands you run all the time, like your test and build scripts. Once those are in place, the prompts you still get are mostly the ones worth reading.

Keep reading about: AIComputersGoogleLinuxProgrammingWindows

Related

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.