Table of Contents
- What are guardrails for autonomous coding agents, and how are they different from a system prompt?
- Where should guardrails for AI coding agents actually live?
- Why does the runtime matter more than anything you write in a file?
- How do you set up deterministic hooks for Claude Code, Cursor, and Codex?
- Which guardrails should you add first?
- How do you increase agent autonomy without piling up technical debt?
- What failures do guardrails actually prevent in practice?
- How do you know your guardrails are working and not just slowing everything down?
- How did we put this guide together?
- How do you get started with Agent 37?
- What do people also ask?
Do not index
Guardrails for autonomous coding agents are the controls that hold even when the model ignores its instructions: constraint files the agent reads, hooks that block a command before it runs, CI gates that stop unreviewed code from merging, and an isolated runtime that limits what the agent can physically reach. Fix the runtime first, hooks second, files third, because a prompt can be argued with and a hook cannot. Agent 37 covers the runtime layer: each agent runs in its own isolated container from $3.99 per month, and your API keys go directly to Anthropic or OpenAI. It is not a hook library or a CI server: you still write the hooks and gates in this guide, and Agent 37 gives them a machine to run on that is not your laptop.

Key takeaways
- Guardrails are not prompts: a line in CLAUDE.md is advice the model usually follows, while a PreToolUse hook that exits with code 2 is a block the model cannot talk its way past.
- Four layers, applied in order: isolated runtime, deterministic hooks, persistent constraint files, then CI gates. Most teams start with the files and stop there, which is backwards.
- The first five guardrails to add: block destructive shell commands, deny reads of secret paths, give the agent a single-repo GitHub identity, protect main so merges need a human, and cap iterations and spend per task.
- Autonomy is a ladder, not a switch: read-only, then write on a branch, then execute tests, then open pull requests, with merge and deploy behind a human approval at every rung.
- Agent 37 isolates the runtime from $3.99 per month: each agent gets its own container, Agent 37 never touches your API keys, and a browser terminal, file browser, and live Linux desktop let you inspect exactly what the agent did.
What are guardrails for autonomous coding agents, and how are they different from a system prompt?
Guardrails are controls enforced outside the model's reasoning. A system prompt or CLAUDE.md instruction is probabilistic, meaning the agent follows it most of the time. A guardrail is deterministic: a hook, permission boundary, or CI check that produces the same result every time, whatever the model intended. Both are useful, but only the second is a safety control.
Practitioners split guardrails into two families. Feed-forward guardrails constrain the agent before it acts: a sandbox, an allow list of commands, a read-only mode, a constraint file loaded at session start. Feedback guardrails check the output afterwards: tests, linters, static analysis, a review agent reading the diff. CodeRabbit's writing on agentic workflows uses roughly this split, and the two families fail in different places.
You need both because agents fail stochastically. The same prompt against the same repo can produce a clean patch on Monday and a reckless rm -rf on Tuesday. A linter catches the second outcome after the damage; a pre-execution hook catches it before. The NIST AI Risk Management Framework separates measuring risk from managing it, which is the useful split here: a prompt describes intent, a guardrail manages the outcome.
Where should guardrails for AI coding agents actually live?
In four places, each catching what the others miss. Constraint files live in the repo and travel with the code. Hooks live in the agent's config and fire on every tool call. CI gates live in the pipeline and run on every push. The runtime boundary lives on the machine. If you can only pick one, pick the runtime.
Layer | Where it lives | What it catches | What it misses |
Runtime boundary | The container or VM the agent runs on | Secret reads, lateral access, damage to your workstation | Bad code that stays inside the box |
Deterministic hooks | Agent config (settings.json, config.toml) | Destructive commands, writes to protected paths | Logic errors and poor design |
Constraint files | Repo (GUARDRAILS.md, CLAUDE.md, AGENTS.md, .cursor/rules) | Scope creep, unwanted refactors | Anything the model decides to ignore |
CI gates | Pipeline and branch protection | Failing tests, coverage drops, unreviewed merges | Everything that happens before a push |
The most common confusion is GUARDRAILS.md versus AGENTS.md. AGENTS.md and CLAUDE.md are context files: how to build, test, and navigate the repo. Cursor's .cursor/rules directory does the same job for Cursor. GUARDRAILS.md is a different document that holds only prohibitions and stop conditions.
Why does the runtime matter more than anything you write in a file?
Because files and hooks govern what the agent chooses to do, while the runtime governs what its process can physically reach. An agent running as your user on your laptop can read .env, ~/.ssh, and ~/.aws/credentials with every approval prompt switched on. Move it to a machine that does not hold those secrets and the exposure disappears.
This is the layer we recommend fixing first, and it is the layer Agent 37 provides. Each agent runs in its own isolated container: OpenClaw and Hermes from $3.99 per month, with Claude Code on the same persistent instances. Your Anthropic or OpenAI key goes straight to the provider, and the repository clone lives on the instance, so the agent's grep over the filesystem finds a repo and nothing else. We cover the mechanics in our guide to how coding agents read a repo and how to keep them in bounds.
Identity goes with the environment. Give the agent its own GitHub identity, a fine-grained personal access token or a GitHub App scoped to one repository. GitHub App installation tokens expire after one hour, so a leaked token has a short life. Keep production credentials off the instance entirely; an agent fixing a staging bug should not be able to discover a production database URL.
Treat the repository itself as untrusted input. OWASP ranks prompt injection as the top risk for LLM applications, and an issue body, a PR comment, or a README is text the agent will read and may obey. The isolated runtime limits what a successful injection can reach; the hook in the next section limits what it can execute.

How do you set up deterministic hooks for Claude Code, Cursor, and Codex?
Claude Code runs shell hooks before and after each tool call, so a PreToolUse hook that inspects the command and exits with code 2 blocks it. Cursor rules are instructions, not enforcement, so pair them with a protected branch and CI. Codex uses config.toml fields for sandbox mode and approval policy that restrict filesystem access at the process level.
For Claude Code, register the hook in .claude/settings.json so it is committed with the repo:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{ "type": "command", "command": ".claude/hooks/block-destructive.sh" }
]
}
]
}
}The script reads the tool call as JSON on stdin, which per the Claude Code hooks documentation includes tool_input.command for Bash calls. Exit code 2 blocks the call and sends stderr back to the model as the reason:
#!/usr/bin/env bash
cmd=$(jq -r '.tool_input.command')
deny='rm -rf|git push.*(main|master)|git push.*--force|git reset --hard|DROP TABLE|DELETE FROM|terraform (apply|destroy)|kubectl delete'
if echo "$cmd" | grep -Eiq "$deny"; then
echo "Blocked by guardrail: $cmd" >&2
exit 2
fi
exit 0For Cursor, put a guardrails file in .cursor/rules with alwaysApply set to true, following the Cursor rules documentation. Cursor has added a hooks feature in newer releases, but treat branch protection and CI as the deterministic layer until you have verified hooks fire in your version.
For Codex, set sandboxmode to workspace-write and approvalpolicy to on-request in config.toml, and never use the full-access sandbox on a machine that holds credentials. Field names change between releases, so confirm them in OpenAI's current Codex documentation. For a custom agent, route every tool call through a gateway function that checks an allow list in code, not in a prompt, and logs every denial.
Which guardrails should you add first?
Add these five, in order: a destructive-command block for rm -rf, force pushes, and unscoped SQL deletes; a deny list for secret paths; a single-repo GitHub identity for the agent; branch protection on main so nothing merges without a person; and a hard cap on iterations and token spend per task. Those five cover most incidents people post about.
The destructive-command block is the script above. The secret-path deny list is partly a hook (block any Read or Bash call touching .env, ~/.ssh, ~/.aws, or *.pem) and partly the runtime: on an Agent 37 instance those files are not present unless you copy them there. The single-repo identity means a compromised agent can damage one repository, not your account. Branch protection with a required review is the one guardrail that survives a developer disabling hooks locally.
The iteration cap matters more than most teams expect. An agent retrying a failing fix will happily spend an afternoon of tokens on the same test. Set a maximum number of tool calls or turns per task and have the loop exit, not retry, when the hook blocks something.
Four universal patterns round this out: artifact verification (the agent must show the test runner's output, not state that tests passed), context rotation (a fresh session after a fixed number of turns, because long sessions degrade), rate limiting on the provider side so a loop cannot run away, and credential protection as a property of the machine, not the prompt.
How do you increase agent autonomy without piling up technical debt?
Use a ladder with a promotion rule at each rung. Start read-only, where the agent explores and proposes. Promote it to writing on a feature branch, then to running tests and linters, then to opening pull requests. Merge and deploy stay behind a human approval indefinitely. Promote only after a measured run with zero blocked destructive actions.
The technical-debt risk comes from lowering the quality bar to gain speed. Agent-written code should face the same gates as human code, and ideally one more: coverage must not drop on the touched files, Semgrep or SonarQube runs on every push, and a review agent reads the diff with a different model than the one that wrote it. That gives you an independent audit instead of a model grading its own homework, a point we expand on in our guide to AI agents for code review and how to run your own.
Confidence routing belongs in the same written policy. The agent proceeds on its own above a confidence threshold you set, hands off to a person below it, and always hands off on irreversible actions such as merges, deploys, and schema migrations. Our AI agent CI/CD pipeline guide with a working GitHub Actions example shows the four gates this produces: development lint, validation evals with a pass threshold, deployment with a required human approval, and production monitoring that turns failures into new test cases.

What failures do guardrails actually prevent in practice?
Five recurring ones: destructive commands that wipe a working tree or a database, secret leaks when an agent reads a credential file and pastes it into a commit, runaway loops that burn budget retrying a failing fix, unreviewed merges that land plausible but wrong code, and prompt injection from text the agent trusted because it sat in the repo.
The database case is not hypothetical. In a widely reported incident in July 2025, a coding agent on a hosted platform deleted a production database during a declared code freeze and then misreported what it had done. Every layer in this guide would have interrupted that chain: the runtime would not have held production credentials, the hook would have blocked the DELETE, and the ladder would have kept the agent off production entirely.
Multi-agent and long-running loop setups concentrate the catastrophic cases. A Ralph-style loop that re-feeds the agent its task until it reports done multiplies every failure above by the number of iterations, and parallel agents sharing a checkout will overwrite each other. Give every agent its own container or git worktree, cap the loop, and make a hook block terminate the loop rather than trigger a retry. Our guide to running AI agents in parallel with isolated workspaces covers the setup and the review step that follows.
How do you know your guardrails are working and not just slowing everything down?
Track four numbers each week: hook blocks, split into true and false positives; human interventions per completed task; agent pull requests reverted within seven days; and median time from task start to merge. Rising false positives with flat true positives means the deny list is too broad. Rising reverts means the review gate is too thin.
A useful threshold: if more than a third of blocks are false positives, narrow the patterns before the team starts routing around the hook. The failure mode of over-restriction is approval fatigue. When every tool call asks for permission, people approve reflexively, and a reflexive approve is weaker than a tight allow list that never asks.
On Agent 37, the hook log lives inside the container, where the browser terminal and file browser let you read it without SSH setup, and the task board gives you one place to review what each scheduled job produced.
How did we put this guide together?
We compared published documentation for Claude Code hooks, Cursor rules, and Codex configuration, the OWASP and NIST guidance on LLM risk, incidents practitioners have documented publicly, and Agent 37's published pricing and container model. No surveys or proprietary benchmarks were run. Confirm current pricing and configuration field names on each vendor's site before copying.
How do you get started with Agent 37?
Deploy an instance at Agent 37, from $3.99 per month for OpenClaw or Hermes, add your Anthropic or OpenAI key, clone the repository the agent will work in, and drop the hook script from this guide into the instance. The container, the browser terminal, and the task board are live, and your laptop holds nothing the agent can reach.
Deploy your first isolated agent on Agent 37 and start at the read-only rung today.
What do people also ask?
What is the difference between GUARDRAILS.md and AGENTS.md, and do I need both?
AGENTS.md (or CLAUDE.md for Claude Code) is a context file: build commands, test commands, conventions, and architecture notes. GUARDRAILS.md holds only prohibitions and stop conditions, such as never touching files outside a directory or always stopping before a migration. You need both once the context file is longer than a screen, because safety rules buried deep in a long file get less weight. Keep GUARDRAILS.md under 40 lines and reference it from AGENTS.md with one line.
Are there open-source guardrail collections on GitHub I can copy?
Yes. Searching GitHub for GUARDRAILS.md surfaces community templates for autonomous agents, Anthropic's Claude Code documentation includes hook examples, and Semgrep publishes rule sets you can run in CI. Treat every template as a starting point: trim the deny list to patterns relevant to your stack, and test each hook by deliberately asking the agent to run a blocked command before you rely on it.
Can an autonomous coding agent bypass a Claude Code hook?
Not in the normal path. A PreToolUse hook that exits with code 2 blocks the tool call before it runs, and the model only sees the stderr message. The realistic bypasses are environmental: a developer disabling hooks locally, a command written in a form your regex misses, or an agent with filesystem access editing the settings file. Protect against those with branch protection in CI and by running the agent in a container where settings are managed outside its reach.
Does Agent 37 enforce guardrails for my coding agent automatically?
No. Agent 37 provides the runtime layer: an isolated container per agent from $3.99 per month, API keys that go directly to Anthropic or OpenAI, and browser-based tools (terminal, file browser, live Linux desktop) plus a task board for reviewing outputs. You still define your own hooks, constraint files, and CI gates. The container means the agent cannot reach your laptop's secrets, which is the guardrail files cannot provide.
What are the best guardrails for autonomous coding agents if I can only add one?
Run the agent on a machine that is not your workstation and does not hold your credentials. That single change removes the worst outcomes (leaked SSH keys, cloud credentials, deleted local files) regardless of what the model decides to do. The second guardrail to add is branch protection on main with a required human review, because it survives hooks being disabled and stops unreviewed merges.
