Guide · Blog Post

AI Coding Agent Guardrails: 10 Controls Every Team Should Enforce

Claude Code, Cursor, Copilot, and Codex no longer just suggest code. They run shell commands, install packages, call APIs, and push branches. That is the point, and it is also the risk: an agent with your terminal has your permissions. In July 2025 Replit's agent erased a production database during a code freeze. In April 2026 a Cursor agent used an over-scoped API token to delete a startup's production volume, backups included, in seconds. Neither needed an attacker. Here are the ten controls I put around every coding agent I run or set up for a client, and why each one exists.

By Mehadi Hasan 10 min read

AI coding agent guardrails: a policy log where npm run test is allowed, git push needs approval, reading .env and production database access are denied, and an unknown outbound host is blocked

The principle: limit the blast radius, not the model

You cannot make a model perfectly obedient, and you cannot make it immune to instructions hidden in a file or web page. What you can control is what it is able to reach and what happens when it gets something wrong. OWASP's Top 10 for Agentic Applications 2026, published in December 2025 and built from real incidents, frames the risks the same way: goal hijack, tool misuse, identity and privilege abuse, supply chain, and unexpected code execution. Every control below either shrinks what the agent can touch or makes its mistakes visible and reversible.

The controls are tool-agnostic. Where I give examples, they come from Claude Code and GitHub Copilot because both document their guardrails clearly.

1. Give the agent its own identity and least-privilege credentials

An agent running in your terminal inherits everything you are logged into: cloud CLIs, database URLs, the GitHub token with admin on every repo. The PocketOS deletion happened because a token meant for one task could delete production infrastructure. The agent did what the token allowed.

  • Separate identity. A dedicated bot account or app identity, so every action is attributable and can be revoked without touching a human's access.
  • Scoped and short-lived tokens. Read access to the repo it is working in, write access to its own branches, nothing else. GitHub's Copilot agent revokes its token when the session ends (GitHub docs).
  • No production credentials, ever. If the agent needs data, give it a staging copy or a read-only replica. Production IAM and deploy rights stay outside the agent.

2. Sandbox the filesystem and the network together

Anthropic's Claude Code sandboxing docs make the key point plainly: you need both layers. Without network isolation, a compromised agent can send out your SSH keys. Without filesystem isolation, it can modify system files to get the network access it was denied.

  • Filesystem: write access to the project directory only. Home directory dotfiles, shell profiles, and other repos are off limits.
  • Network: deny by default, with an allowlist for your package registries and the APIs the task genuinely needs. Copilot's coding agent ships with a firewall enabled for exactly this reason.
  • Know the sandbox's edges. Claude Code's built-in sandbox restricts Bash commands; file tools, MCP servers, and hooks still run on the host. For fully unattended runs, run the whole agent inside a container or VM, which is what Anthropic recommends before using --dangerously-skip-permissions (sandbox environments).

Sandboxing also makes agents more useful, not less. Anthropic reports it cut permission prompts by 84% in its internal use, because safe commands no longer need a human to approve each one (Anthropic). Fewer prompts also means less approval fatigue, which is its own security problem.

3. Keep secrets out of the agent's reach

Anything the agent can read can end up in its context, its logs, a commit, or an outbound request. Treat .env files, ~/.ssh, ~/.aws, and credential stores as unreadable. Where the agent needs to call an authenticated service, use a proxy or a narrowly scoped tool that performs the action without ever exposing the key. Add secret scanning to pre-commit and CI so a leaked key is caught before it lands on a branch.

4. Write the permission policy down and version it

"Ask me before anything risky" is not a policy. Most agents now support explicit allow, ask, and deny rules. Put them in the repository so every developer and every CI run gets the same rules, and use managed settings to enforce the ones nobody should be able to switch off. A starting point for Claude Code:

.claude/settings.json

{
  "permissions": {
    "allow": [
      "Bash(npm run test:*)",
      "Bash(npm run lint)",
      "Bash(git diff:*)",
      "Bash(git status)"
    ],
    "ask": [
      "Bash(git push:*)",
      "Bash(npm install:*)"
    ],
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(~/.ssh/**)",
      "Read(~/.aws/**)",
      "Bash(curl:*)",
      "Bash(rm -rf:*)"
    ]
  }
}

Pattern rules are a first line, not a wall: a determined or confused agent can reach the same result through a different command. That is why this control sits on top of the sandbox in control 2, not instead of it. For checks a pattern cannot express, a pre-tool hook can inspect each call and block it with a reason (Claude Code hooks).

5. Require a human for anything irreversible, and keep it recoverable

Deleting data, running migrations, deploying, rotating keys, sending email, spending money, and force-pushing all need a person to say yes, every time. Instructions in a prompt are not enough: in the Replit case the agent had been told repeatedly not to touch production. The approval has to be enforced by the tooling.

Assume an approval will one day be clicked by a tired person. Backups must live somewhere the agent's credentials cannot reach. PocketOS lost its backups along with the database because both sat on the same volume behind the same token.

6. Branch, pull request, CI: never straight to main

The agent works on its own branch and proposes changes through a pull request. Branch protection, required reviews, and required status checks then apply to agent code exactly as they apply to a junior developer's. GitHub builds this into Copilot's coding agent: it can only push to its own copilot/ branches, cannot commit to the default branch, and workflows on its pull requests need approval from someone with write access before they run (GitHub docs). GitHub added an option to skip that approval in March 2026, so check that nobody has turned it off.

The person who prompted the agent should not be the only reviewer. Agent pull requests tend to be large and plausible, which is the combination reviewers skim.

7. Make tests and checks the definition of done

An agent will report success with confidence whether or not the code works. The only reliable signal is a check it cannot argue with: the test suite, type checks, linters, a security scanner, and a dependency audit, run in CI on every agent pull request. Two rules help in practice: the agent may not edit or delete existing tests to make them pass without that change being called out in review, and new code needs new tests. Copilot's agent runs CodeQL and checks new dependencies against the GitHub Advisory Database for the same reason.

8. Treat everything the agent reads as untrusted input

Issues, pull request comments, README files, dependency source, web pages, and tool output can all contain instructions aimed at the agent. Simon Willison's "lethal trifecta" explains when that becomes dangerous: an agent that has access to private data, is exposed to untrusted content, and can communicate externally can be steered into leaking that data. Most coding agents have all three by default.

No filter reliably catches prompt injection, so the practical defence is to break at least one leg of the trifecta for each task. An agent that triages public issues should not also hold your secrets. An agent with access to private code should not have open network egress. The egress allowlist from control 2 is often the cheapest leg to remove.

9. Vet the agent's supply chain: MCP servers, skills, extensions

Every MCP server, skill, and plugin you add runs with the agent's access. In July 2025 a malicious prompt instructing the agent to wipe local files and cloud resources was merged into the Amazon Q Developer extension for VS Code and shipped in version 1.84.0; AWS said it did not execute because of formatting mistakes, and pulled it the next day. In February 2026 researchers found 341 malicious skills on ClawHub, the community hub for OpenClaw (The Hacker News).

  • Keep an allowlist of approved MCP servers and skills, and read each one before approving it.
  • Pin versions, so a server you reviewed cannot quietly change what its tools do.
  • Give each MCP server its own scoped credentials, and prefer read-only modes where they exist.
  • Patch the agent and its sandbox like any other dependency. Sandbox escapes and approval bypasses have already been found and fixed in several agents.

I review public skill packs and MCP servers, including what they can access, in my AI skills directory and MCP directory.

10. Log everything and set hard limits

When something goes wrong you need to answer three questions quickly: what did the agent run, what did it change, and what did it send out. Keep an audit trail of every shell command, file write, and network request, stored where the agent cannot edit it. Hooks that log each tool call are an easy start.

Then cap the runaway cases: a time limit per command, a step or time budget per task, and a spending limit on the model API key. A stuck loop that retries a failing deploy for an hour is a cost problem at best and an outage at worst.

How much of this you need

Not every setup needs all ten on day one. What changes the answer is how much the agent does without a person watching:

SetupMinimum controlsAdd next
One developer, supervised, local3 secrets, 4 permission policy, 5 approvals, 6 branch and PR2 sandbox, so you can approve less
A team using agents dailyAll of the above, plus 1 identity, 7 CI checks, 9 approved MCP and skill list10 logging, via managed settings
Unattended agents (CI, scheduled, cloud)All ten, with the agent in a container or VM and default-deny egressRegular review of the audit logs

The same thinking applies beyond code. Business agents that touch your CRM or monday.com boards need the same identity, approval, and logging controls; I covered that side in OpenClaw vs n8n and connecting Claude to monday.com with MCP.

Want a second pair of eyes on your agent setup?

Tell me which agents your team uses, what they can access, and how changes reach production. I will reply within 1 business day with the gaps I would close first. See my AI agent development service.

Get my free automation review

Frequently asked questions

What controls should every AI coding agent follow?

At minimum: its own least-privilege identity with no production credentials, a filesystem and network sandbox, no access to secrets, a written allow/ask/deny permission policy, human approval for irreversible actions, changes only through branches and pull requests with CI, untrusted-input handling for prompt injection, a vetted list of MCP servers and skills, and audit logs with time and cost limits.

Is it safe to run Claude Code with --dangerously-skip-permissions?

Only inside an isolated container or VM with no production credentials and restricted network access. Anthropic recommends exactly that, because the built-in sandbox restricts Bash commands while file tools, MCP servers, and hooks still run on the host.

Can AI coding agents be prompt injected?

Yes. Instructions hidden in issues, comments, files, web pages, or tool output can steer an agent. No filter reliably stops this, so limit the damage: do not give one agent private data, untrusted content, and open network access at the same time.

Should an AI agent be allowed to push to main?

No. Agents should work on their own branches and propose changes through pull requests, with branch protection, required reviews, and required CI checks applied exactly as for a human developer. GitHub's Copilot coding agent is limited to its own copilot/ branches for this reason.

Are MCP servers and agent skills a security risk?

They run with the agent's access, so treat them like dependencies. Malicious code has already shipped in an AI coding extension and in hundreds of community skills. Keep an approved list, read each one, pin versions, and give each its own scoped credentials.

Details checked November 17, 2026 against OWASP, Anthropic, and GitHub documentation and the sources linked above. Agent permission models change quickly; check your tool's current docs before rolling out.