By Ayena TCHIKPE, founder and software engineer Published
In this article
In short
- Guardrails for AI coding agents work in layers. A permission rule matches the text of a command, a sandbox restricts the process. You need both.
- The checks that matter live outside the agent, in git hooks and CI. The agent can be talked out of a rule in its prompt, not out of a required status check.
- Unattended runs need the strictest setup. Headless agents skip the trust prompts a human would see.
- Start with five items, not fifty. Secrets out of reach, a sandbox that fails closed, no direct push to main, tests green before merge, and logs you actually read.
Coding agents now open pull requests on their own. Claude Code, Cursor, Codex CLI and GitHub Copilot's cloud agent run shell commands, install packages and push branches. The usual path is familiar: the developer approves every command at first, then turns on auto-approve because the prompts slow everyone down.
That is the moment you need guardrails for AI coding agents that don't depend on someone reading every prompt. This checklist is the one we use when we set up a repository for agent work. It follows the agent loop: before the agent runs, while it runs, on its output, at merge and deploy, and after. Each item says what to do, why, and how to enforce it with a real setting or tool.
Every setting below was checked in the vendor's documentation on 8 November 2026. These tools change often: check again before you copy.
One idea runs through the whole list. OWASP's guidance on excessive agency (LLM06:2025) says it plainly: implement authorisation in downstream systems "rather than relying on an LLM to decide if an action is allowed or not". An agent that has read a malicious README will happily ignore your instructions in AGENTS.md. It cannot ignore a sandbox, a ruleset or a failing CI job. The risk is climbing: in the 2026 edition of its LLM Top 10, released in August, OWASP moved excessive agency up to third place, behind prompt injection and sensitive information disclosure, according to Help Net Security.
Before the agent runs: permissions, sandbox, secrets
This is where most of the risk is removed. OWASP's Top 10 for Agentic Applications (published 9 December 2025) puts agent goal hijack (ASI01) and tool misuse (ASI02) at the top of its list. Both start with what the agent can reach.
1. Turn the sandbox on, and make it fail closed.
- Why: permission rules decide whether a command runs; the sandbox decides what it can touch once it runs.
- How: in Claude Code the sandbox is off by default. Set
sandbox.enabled: true, plussandbox.failIfUnavailable: trueso the session exits instead of running unsandboxed, andsandbox.allowUnsandboxedCommands: falseto remove the escape hatch. Native Windows is not supported. In Cursor, pick the Auto-review or Allowlist run mode, never "Run Everything", which runs every tool call with no sandbox and no classifier.
2. Close the reads, not only the writes.
- Why: by default the Claude Code sandbox lets commands read most of the machine, including
~/.sshand~/.aws/credentials. - How: add
sandbox.filesystem.denyReadfor your home directory andallowReadfor the project, or usesandbox.credentialsto deny or mask credential files and environment variables. In Cursor, switch read access from the default "System" to "Workspace".
3. Deny secret files to the agent's own tools too.
- Why: in Claude Code, the built-in Read and Edit tools, WebFetch, MCP servers and hooks run outside the sandbox.
- How:
permissions.denywithRead(./.env),Read(./.env.*),Read(./secrets/**). A.claudeignorefile has no effect; the docs say to move its entries into deny rules. In Cursor,.cursorignoreis a protected path the sandbox won't let the agent rewrite.
4. Allow the network by domain, nothing else.
- Why: exfiltration needs a way out. A deny rule on
curldoesn't matchsh -c "curl …"or/usr/bin/curl; the docs say so explicitly. - How:
sandbox.network.allowedDomainsstarts empty. List your registry and your git host, nothing more. In Cursor, the default network mode adds a built-in list of package managers and language tools to whatsandbox.jsonallows; keep that file short.
5. Lock the dangerous modes at organisation level.
- Why: one developer's "skip all prompts" setting becomes everyone's incident.
- How: in Claude Code managed settings, set
permissions.disableBypassPermissionsMode: "disable"(anddisableAutoModeif your policy requires it). A repository's project settings cannot switch onbypassPermissionsorauto. Cursor team settings override the per-userpermissions.json.
6. Treat everything the agent reads as untrusted input.
- Why: indirect prompt injection arrives through files, issues, web pages and tool output, not through your prompt.
- How: OWASP LLM01 recommends to "segregate and identify external content" and to require human approval for high-risk actions. In practice: no auto-approve on sessions that read issues or web content from outsiders; review every
.mcp.jsonserver like a dependency (OWASP lists agentic supply chain compromise as ASI04); and give the agent tokens scoped to one repository, short-lived where your platform allows it.
7. Unattended runs get the strictest profile.
- Why:
claude -pshows no workspace trust dialog and no MCP approval prompt, yet it runs the hooks in the repository's.claude/settings.jsonand connects the servers in its.mcp.json. - How: in CI, run with
--bare, which skips hooks, plugins, MCP servers andCLAUDE.mdfrom the working directory, and pass only the settings you want with--settings. For a pull request from a fork, that difference is the whole threat model. The catch: hooks don't run in bare mode, even when passed with--settings, so in those runs the gates from items 9 and 10 must live in CI steps and git hooks.
While it runs: command rules, hooks and limits
8. Write allow and deny lists, and know their limit.
- Why: they cut the noise and stop the obvious mistakes, but they match command text.
- How: Claude Code evaluates deny, then ask, then allow, and a deny rule from any scope beats an allow rule from any other. Allow
Bash(npm run test *), ask onBash(git push *), denyBash(git push --force *). Compound commands are split, soBash(npm *)doesn't approvenpm test && rm -rf build. Treat these lists as hygiene, and the sandbox as the boundary.
9. Block the shortcuts with a pre-tool hook.
- Why: some rules need logic a pattern can't express, such as "no
--no-verify, ever". - How: a Claude Code
PreToolUsehook that exits with code 2 blocks the call and sends its stderr to the model as the reason. A hook returning "allow" never overrides a deny rule. Copilot CLI and Codex CLI have their own hook points; keep the logic in one script they all call.
10. Don't let the agent say "done" while checks are red.
- Why: the failure to plan for is not malice, it is a confident summary over a failing test suite.
- How: a
Stophook that runs lint, types and tests and exits with code 2 when they fail. Claude Code then keeps working instead of ending its turn, with your error output in front of it.
11. Cap turns and spend on headless runs.
- Why: a loop retrying the same broken fix all night costs money and proves nothing.
- How:
--max-turnsand--max-budget-usd, both print mode only. The budget is checked against a client-side estimate and spend can pass the cap, so leave headroom. Add a job-level timeout in your CI runner as a second limit.
12. Watch for changes to the guardrails themselves.
- Why: an agent that edits its own settings file has removed your checklist.
- How: the Claude Code sandbox keeps
.claudesettings,.mcp.jsonand.git/hookswrite-protected for shell commands, but the Edit tool runs outside the sandbox: addEdit(./.claude/**)andEdit(./.mcp.json)topermissions.deny. Add aConfigChangehook to log or block settings changes during a session, and aCODEOWNERSentry on these paths so a change needs a named reviewer.
On its output: what the diff must pass
These checks run on the diff, the same way for humans and agents.
13. Limit the size of a change.
- Why: a 4,000-line agent diff will be approved without being read.
- How: we found no native "maximum diff size" rule in GitHub, so add a short CI step. Pick a threshold such as 400 changed lines and tune it per codebase. Your checkout needs the base branch history, and the step fails if git can't compute the diff.
stat=$(git diff --numstat origin/main...HEAD) || exit 1
changed=$(printf '%s\n' "$stat" | awk '{s+=$1+$2} END {print s+0}')
[ "$changed" -le 400 ] || { echo "Diff too large: $changed lines. Split it."; exit 1; }
14. Protect the paths an agent should never touch.
- Why: CI workflows, infrastructure code and migrations change what runs in production.
- How: GitHub push rulesets can restrict file paths, file extensions and file size for private and internal repositories, and they apply to the whole fork network. Add
CODEOWNERSwith "require review from code owners" for.github/workflows/,infra/and the agent configuration.
15. Require tests, and refuse silenced tests.
- Why: an agent under pressure to turn CI green can skip the test instead of fixing the code.
- How: the required checks run the full suite. Add a check that fails on new
.skip,xit,@Ignoreoreslint-disablelines unless the commit carries a written reason.
16. Run static analysis on every pull request.
- Why: OWASP lists unexpected code execution (ASI05), and GitHub's own docs warn that Copilot "can produce incorrect or suboptimal code, including code that contains security vulnerabilities".
- How: CodeQL with the ruleset rule "require code scanning results", or
semgrep ci, which can report only the findings a change introduces.
17. Scan for secrets before the push, and again in CI.
- Why: an agent that printed a token into a test fixture will commit it.
- How: a pre-commit hook plus a CI job. Gitleaks still works (
gitleaks git,gitleaks dir, thegitleaks/gitleaks-action), but its README now says it is feature complete and will receive security patches only, with the maintainer moving to Betterleaks. On GitHub, add the ruleset rule "require secret scanning alerts to be resolved" (public preview).
18. Check every new dependency.
- Why: agents add packages freely, and a misspelt package name is exactly what typosquatters count on.
- How:
actions/dependency-review-action@v5withfail-on-severityanddeny-packages. Copilot's cloud agent already checks new dependencies against the GitHub Advisory Database for malware and High or Critical CVSS vulnerabilities.
19. Check licences.
- Why: one copyleft package in a proprietary product is a legal question, not a code review comment.
- How:
allow-licensesin the same action, with SPDX identifiers (deny-licensesis deprecated). GitHub rulesets also offer "require license compliance results before merging".
At merge and deploy: CI gates and human review
20. No direct push to main, no force push.
- How: a ruleset with "require a pull request before merging" and "block force pushes". Check the bypass list: a rule your agent's token can bypass does not block it.
21. A human approves, and not the one who asked the agent.
- Why: the person who prompted the change already believes it is right.
- How: ruleset options "require approval of the most recent reviewable push" and "require approval from someone other than the last person to push", plus "dismiss stale approvals". For Copilot's cloud agent, GitHub already prevents the requester from approving the pull request and requires an extra approval on pull requests opened under Copilot's own identity.
22. Workflows don't run on agent code until a human says so.
- How: by default, GitHub doesn't run Actions on Copilot's pull requests until someone with write access clicks "Approve and run workflows". Keep that default. For other agents, use
pull_requestrather thanpull_request_targetand give the workflow token read-only permissions.
23. Make every merge reversible.
- Why: the guardrails will miss something one day.
- How: this is practice, not a tool: one small change per pull request, squash merges, database migrations that can run backwards, and a deploy that can return to the previous build with one command. Test the rollback before you need it.
This is the part of the work our DevOps service covers: rulesets, required checks and a pipeline you can roll back.
After: audit logs and the metrics to watch
24. Keep a log of what the agent tried, not only what it shipped.
- How: Claude Code exports OpenTelemetry once
CLAUDE_CODE_ENABLE_TELEMETRY=1is set. Theclaude_code.tool_decisionevent records each permission decision and its source;claude_code.api_requestrecords cost and tokens. Prompt content is redacted by default. Git history and the pull request close the loop: Copilot's cloud agent links each commit to its session logs.
25. Watch four numbers every week.
- Blocked actions per session. A sudden rise means a new pattern or a hijack attempt.
- Edit rejections, from
claude_code.code_edit_tool.decision. If developers reject most edits, the agent's context or instructions are wrong. - Cost per merged pull request, from
claude_code.cost.usageand your merge count. - Reverted agent pull requests. The clearest sign of whether review works.
26. Re-run the audit after every tool update.
- Why: defaults change between versions. Until v2.1.257, for example, Claude Code still honoured
bypassPermissionsfrom a repository's settings file. - How: read the changelog, then try the forbidden actions again yourself.
The printable guardrails checklist
| # | Stage | Guardrail | Enforced by |
|---|---|---|---|
| 1 | Before | Sandbox on, fails closed | sandbox.enabled, failIfUnavailable |
| 2 | Before | Reads limited to the project | filesystem.denyRead, Cursor "Workspace" |
| 3 | Before | Secret files denied to agent tools | permissions.deny Read(./.env) |
| 4 | Before | Network by allowlist only | network.allowedDomains, Cursor sandbox.json |
| 5 | Before | Bypass modes locked | Managed disableBypassPermissionsMode |
| 6 | Before | Untrusted content handled as such | Scoped tokens, MCP review, no auto-approve |
| 7 | Before | Headless runs isolated | claude -p --bare --settings |
| 8 | During | Allow, ask and deny lists | permissions rules |
| 9 | During | Shortcuts blocked | PreToolUse hook, exit 2 |
| 10 | During | No "done" on red checks | Stop hook, exit 2 |
| 11 | During | Turns, budget, timeout | --max-turns, --max-budget-usd, CI timeout |
| 12 | During | Guardrail files protected | Sandbox protected paths, ConfigChange, CODEOWNERS |
| 13 | Output | Diff size limit | CI step |
| 14 | Output | Protected paths | Push rulesets, code owners |
| 15 | Output | Tests required, none silenced | Required checks, skip detector |
| 16 | Output | Static analysis | CodeQL, semgrep ci |
| 17 | Output | Secret scanning | Pre-commit + CI, ruleset |
| 18 | Output | Dependency check | dependency-review-action@v5 |
| 19 | Output | Licence check | allow-licenses |
| 20 | Merge | No direct or force push | Ruleset |
| 21 | Merge | Independent human approval | Ruleset review options |
| 22 | Merge | Workflows approved by a human | Actions approval, read-only token |
| 23 | Deploy | Rollback tested | Pipeline, reversible migrations |
| 24 | After | Agent actions logged | OpenTelemetry, session logs |
| 25 | After | Four weekly metrics | Dashboard |
| 26 | After | Audit after each update | Changelog review, manual tests |
Where to start, and where aycod fits
Twenty-six items is a lot for one sprint. Our advice: start with the five that stop real damage. Secrets out of reach (items 2 and 3), a sandbox that fails closed (1), no direct push to main (20), tests green before merge (10 and 15), and a log someone reads (24). Add the rest as your agents take on more work.
Coding agents needed one guardrail, the same on the developer's machine and in CI, whatever the technology. That is why we built aycod, our open-source guardrail: one small binary that stands between the AI agent and the repository: it runs your own checks, refuses the shortcuts and gives the same verdict in CI on every pull request. One command equips a project with git hooks, agent hooks for Claude Code, Codex CLI and Copilot CLI, and rules in AGENTS.md. It refuses force pushes, direct pushes to main, skipped git hooks and reads of secrets (.env, keys, cloud credentials), and it won't let a task end, a commit go through or a push leave until lint, types and tests are green. It runs on Linux, macOS and Windows, in GitHub Actions, GitLab CI or any runner. We run it on our own projects, including Asimé, our online shop platform in production. It covers items 3, 9, 10, 15 and 20 of this list; the sandbox, rulesets, dependency and licence checks are still yours to configure.
If you want this in place, that is what our AI agent guardrails service does: we audit how your agents work today, set up the rules, hooks, sandbox and quality gate in your repositories, then try the mistakes ourselves and show you they are blocked. Tell us by email which agents you use, where your code lives and what scares you most, and we will reply with where we would start.
Sources (as of 8 November 2026): Claude Code, Configure permissions · Claude Code, Sandboxing · Claude Code, Hooks reference · Claude Code, Run Claude Code programmatically · Claude Code, CLI reference · Claude Code, Security · Claude Code, Monitoring usage · Cursor, Run modes · GitHub, Available rules for rulesets · GitHub, About rulesets · GitHub, Risks and mitigations for Copilot cloud agent · GitHub, dependency-review-action · Gitleaks README · Semgrep, Add Semgrep to CI · OWASP, LLM06:2025 Excessive Agency · OWASP, LLM01 Prompt Injection · OWASP, Top 10 for Agentic Applications for 2026 · OWASP, GenAI LLM Top 10 2026 · Help Net Security, OWASP 2026 LLM Top 10 released (6 August 2026).
