Get the free coreGet core

AI guardrails: what they are and what they can't stop

Updated 6 min readSection 05 / Threats
SHORT ANSWER

AI guardrails are checks placed around a model or an agent. They filter what goes in, filter what comes out, or limit what the agent is allowed to do. Some are guesses: a second AI model, called a classifier, reads each action and approves or blocks it, as in Claude Code's auto mode. Others are fixed rules enforced by the program or by the operating system. None is a guarantee, because it is unclear whether any fool-proof way to stop prompt injection exists. First action in Claude Code: run /sandbox to turn the sandbox on, then check each guardrail you rely on: is it a rule or a guess?

You may know AI guardrails from the cloud side, where they wrap a chatbot. If you run a coding agent on your Mac, they matter more, because the agent can run commands on the machine that holds your keys and projects. This page sorts the types, shows which kind each one is, and says plainly what none of them stops.

01What AI guardrails are

A guardrail is a safeguard that sits between the model and the world. Cloud products offer configurable safeguards that detect and filter undesirable content and protect sensitive information. A content filter can scan prompts and responses to block harmful, offensive or insecure content.

For an agent that acts, the word covers more than filtering text. It also covers what the agent is allowed to do. OWASP is the security group behind well-known top-ten lists for web and AI apps. It defines excessive agency as the weakness that lets damaging actions happen in response to unexpected, ambiguous or manipulated model output, whatever caused the model to misbehave. Guardrails for agents are the controls against that.

02Types of guardrails, side by side

TypeWhat it doesReal exampleWho enforces it
Content filterScans prompts and replies for harmful contentAmazon Bedrock Guardrails, GitHub's filterA filtering service
Model reviewA second model judges each action before it runsClaude Code auto mode, Cursor Auto-reviewAnother model, which can be wrong
Written instructionsYou tell the model what not to doA system prompt, or a CLAUDE.md file, the text file of instructions a project keeps for Claude CodeThe model itself; CLAUDE.md does not change what Claude Code allows
Permission rulesAllow, ask or deny a tool call by patternClaude Code rulesThe program, not the model
HookYour own script runs before a tool call and can block itClaude Code PreToolUse hook, the one that fires before a tool callYour script, not the model's choice
SandboxThe operating system fences what commands can touchSeatbelt, the sandbox framework built into macOSThe OS, whatever the model ran
Human approvalA person confirms the action firstA permission promptYou

A hook is a small script that Claude Code runs at fixed points, for example just before a tool call. A sandbox is a fenced area: the operating system limits what a command can read, write and reach. The comparison is on the sandbox page.

03Rules and guesses are different things

The last column of the table is the one that matters. Model review is a guess. Cursor's review classifier can allow a call you would have blocked, or block one you would have allowed, and Auto-review is not a security boundary. Auto mode in Claude Code reduces permission prompts but does not guarantee safety.

Rules do not depend on the model's mood. A sandbox holds regardless of what the model chose to run. A hook gives deterministic control, meaning certain actions always happen rather than relying on the model to choose them. Cursor's own advice for teams is to pair best-effort guardrails with deterministic ones.

So put a hard limit underneath and add a model reviewer on top for convenience. In Claude Code the first two steps are short. Run /sandbox to turn the sandbox on. Then add an Edit deny rule, a rule that forbids a tool call, under permissions.deny in .claude/settings.json. For the .env file in the project root it looks like this, in the same JSON form as the docs example:

{ "permissions": { "deny": ["Edit(/.env)"] } }

The page on AI agent guardrails maps all the layers for a coding agent.

04What guardrails can't stop

The first gap is prompt injection. That is text slipped into something the model reads, such as a web page or a file, which the model then treats as instructions. Such text does not need to be readable by a human, as long as the model parses it. It is unclear whether fool-proof prevention exists, so mitigations reduce impact and do not remove the problem. Simon Willison put it bluntly: "Guardrails won't protect you", because "we still don't know how to 100% reliably prevent this from happening". More detail on prompt injection.

The second gap is instructions. A restriction written in a system prompt may be bypassed through prompt injection. That is why the table marks written instructions as soft.

The third gap is the output. If model output goes straight into a system shell, the result can be remote code execution, which means someone else's commands running on your machine. OWASP's advice is to treat the model like any other user, with zero trust.

The fourth gap is the rules themselves. A deny rule does not match the same program called by its path or inside sh -c. The page on AI agent permissions covers where rules are strong and where they leak.

05How to use LLM guardrails on a coding agent

Start with least privilege: restrict what the model can do to the minimum its job needs. In practice that means a sandbox or a deny rule for the things that must never happen, and not an instruction.

Then add review where the cost of a mistake is high. OWASP recommends human-in-the-loop control, so a person approves high-impact actions before they happen. Auto mode does not let its classifier judge removals such as rm -rf / or rm -rf ~ by default. In the terminal it asks you to approve them instead. That question to you can still miss some commands, so it is no replacement for an operating-system control such as the sandbox. Keep the sandbox on as the hard limit for deletions.

Last, do not build on a mode with the guardrails switched off. Claude Code's --dangerously-skip-permissions flag stops the permission prompts, and nothing takes their place: protected path checks are also skipped, and only the actions no mode auto-approves still apply. Codex's equivalent flag runs with no sandbox and no approvals, and Cursor's Run Everything mode runs every tool call automatically. The story of that Claude Code flag is on dangerously-skip-permissions.

06Where to go next

Each neighbouring page takes one layer. Hooks shows how to write your own check, auto mode lists what the classifier blocks and allows, and AI agent firewall covers limiting where an agent can connect. For seeing what actually happened, read AI agent monitoring.

A guardrail tries to stop an action before it runs and leaves no record of what did. Guardrails decide what may run; to see what did run, Artificial Immunity's free, open-source core watches Claude Code, Cursor and Codex sessions on your Mac and reports what it finds, without stopping anything.

07The short version

AI guardrails come in two kinds: rules that code enforces and guesses that a model makes. Rely on the rules for anything you cannot undo, use the guesses for convenience, and remember that no guardrail yet reliably stops prompt injection.

FAQ

What is a guardrail in AI?

A guardrail is a check placed around a model or an agent. It filters what goes in, filters what comes out, or limits what the agent may do. Amazon describes its own product as configurable safeguards that detect and filter undesirable content.

What are examples of AI guardrails?

Content filters, a second model that reviews actions, permission rules, hooks, an operating system sandbox, human approval and least privilege. The table on this page puts each one next to a real example.

What are the different types of guardrails in an LLM?

This page sorts them into seven kinds: content filters, model review, written instructions, permission rules, hooks, sandboxes and human approval. They split into guesses made by a model and rules enforced by code.

Which setups have the guardrails switched off?

The no-prompt modes: Claude Code's --dangerously-skip-permissions flag, Codex's --dangerously-bypass-approvals-and-sandbox flag, also called --yolo, and Cursor's Run Everything mode, where every tool call runs automatically.

How to use LLM guardrails?

Pick one hard limit first, such as a sandbox or a deny rule. Add model review on top for convenience. Keep a human approval step for actions you cannot undo.

Sources

  1. Amazon Bedrock docs: Guardrails
  2. GitHub docs: Copilot code completion, responsible use
  3. Claude Code docs: permission modes
  4. Claude Code docs: permissions
  5. Claude Code docs: hooks guide
  6. Claude Code docs: sandboxing
  7. Cursor docs: run modes
  8. Cursor docs: enterprise security hardening
  9. OWASP GenAI: LLM01 Prompt Injection
  10. OWASP GenAI: LLM06 Excessive Agency
  11. OWASP GenAI: LLM05 Improper Output Handling
  12. Simon Willison: the lethal trifecta
  13. Artificial Immunity
Guardrails try to stop a bad action. Artificial Immunity watches the Mac where your agents work and reports what ran.Get the free core