AI Agent Security and Guardrails: A Production Guide

An AI agent is only as safe as the controls around it. Guardrails that hold up in production limit what an agent can read, which actions it can take, where its commands run and what it can send out. They keep working after a prompt injection has convinced the model to misbehave. Instructions in a system prompt help the model behave well, but they do not enforce anything.

This guide is the overview for FindPicked’s articles on AI agent security. It covers the threat model, a layered checklist, sandboxing options, prompt injection, secret leakage and human approval, and it links each claim to its primary source. The container and secret-scanning examples were run locally on 17 November 2026 with Docker 29.5.3 and gitleaks 8.30.1. Nothing here is a penetration test of a specific product.

Why agents need different security thinking

A chatbot that answers questions can embarrass you. An agent that runs commands, calls APIs and reads your files can act on a bad instruction. Three public frameworks describe the risk:

  • Prompt injection is first in the OWASP Top 10 for LLM Applications 2025. Indirect injection arrives through content the model processes, such as web pages, files, issues or tool results. OWASP says it is unclear whether fool-proof prevention exists, so its advice focuses on limiting impact: least privilege, human approval for high-risk actions and clear separation of untrusted content.
  • Excessive agency (OWASP LLM06) is what turns a manipulated output into a damaging action. OWASP traces it to excessive functionality, excessive permissions and excessive autonomy.
  • Agent-specific risks now have their own list. The OWASP Top 10 for Agentic Applications, published on 9 December 2025, starts with Agent Goal Hijack, Tool Misuse and Identity & Privilege Abuse. It also covers Memory & Context Poisoning and Cascading Failures.

Two rules of thumb help when you review a design. Simon Willison’s lethal trifecta warns that an agent with access to private data, exposure to untrusted content and the ability to communicate externally can be tricked into sending that data to an attacker. Meta’s Agents Rule of Two turns this into a design constraint. Within one session, an agent should have no more than two of three properties: processing untrustworthy inputs, access to sensitive systems or private data, and the ability to change state or communicate externally. If a task needs all three, Meta says the agent should not run autonomously and needs human approval or another reliable check.

A six-layer guardrail checklist

No single control is enough. OpenAI’s practical guide to building agents calls guardrails “a layered defense mechanism” and says they should be paired with authentication, authorization and strict access controls. The table groups the controls by the question each layer answers.

Layer Question it answers Typical controls
1. Scope What can the agent do at all? The fewest tools that solve the task; narrow tools instead of an open shell or open URL fetching; read-only variants
2. Identity Whose authority does it use? A separate identity per agent; short-lived, scoped credentials; acting in the user’s context instead of with a shared admin key
3. Isolation Where do its commands run? OS sandbox, container or VM with only the workspace mounted; network egress off or allowlisted
4. Action gates Which actions need a check? Deny, ask and allow rules; human approval for irreversible or high-stakes actions; authorization enforced by the target system
5. Data flow What goes in and what comes out? Untrusted content marked as data; outputs validated by code; outbound destinations blocked or allowlisted
6. Detection and response How would you notice, and how fast can you stop it? Tool-call logs; secret scanning; alerts on unusual actions; a tested way to revoke credentials and stop runs

Layers 1, 2 and 4 follow OWASP’s excessive agency mitigations: minimize extensions, avoid open-ended extensions, execute extensions in the user’s context, require user approval, and use “complete mediation,” which means downstream systems enforce authorization instead of trusting the model. OpenAI’s guide adds a practical step for layer 4. Rate each tool as low, medium or high risk based on read versus write access, reversibility, required permissions and financial impact, then gate the high-risk tools.

Prompt and data injection: design for it

Filtering alone cannot solve injection, because the model cannot reliably tell instructions from data. Classifiers and cautious prompts reduce noise, but a detector that misses a small share of attacks still fails as a security control. Willison points out that 95% detection would be “very much a failing grade” in web application security.

Design patterns give stronger guarantees by limiting what injected text can influence. Design Patterns for Securing LLM Agents against Prompt Injections (Beurer-Kellner et al., 2025) describes six:

  • Action-Selector: the model only picks from predefined actions and never sees their results.
  • Plan-Then-Execute: the plan is fixed before untrusted data is read, so that data cannot add actions.
  • LLM Map-Reduce: isolated model calls each handle one untrusted item, and a separate step combines their constrained outputs.
  • Dual LLM: a privileged model with tools hands untrusted text to a quarantined model that has no tools.
  • Code-Then-Execute: the agent writes a program first and then runs it over the untrusted data.
  • Context-Minimization: content that is no longer needed is removed before later steps.

The authors state the cost plainly: these patterns “constrain the actions of agents to explicitly prevent them from solving arbitrary tasks.” The CaMeL paper (Debenedetti et al., 2025) separates control flow from data flow; its abstract reports 77% of AgentDojo tasks solved with provable security, against 84% for an undefended system.

For most teams, the practical version is to break the trifecta per session. An agent that triages public issues should not hold production credentials. An agent with production access should not browse the open web. When a task needs both, put a human approval step before anything leaves the system. MCP servers add injection paths through tool descriptions and tool results; the MCP guide covers them.

Sandboxing: match the boundary to the risk

A sandbox decides what a successful attack can reach. The common options differ in strength:

Option What it constrains Good fit Limits to know
Tool permission rules The agent’s own tool calls Interactive work with a person watching Claude Code’s docs say a Bash rule “isn’t a security boundary” around the program, and Read deny rules do not stop a script that opens files itself (permissions)
Built-in OS sandbox File and network access of shell commands Local coding agents Claude Code’s sandbox is off by default and, unless configured, can still read most of the machine, including ~/.ssh and ~/.aws/credentials (sandboxing)
Container Everything inside the container CI jobs, untrusted repositories, batch runs Shares the host kernel; only as strong as its mounts and network settings
VM or remote ephemeral environment A whole guest system Untrusted code at scale More setup, cost and start-up time

Claude Code’s sandbox uses Seatbelt on macOS and bubblewrap on Linux and WSL2. It sends network traffic through a local proxy that checks each hostname against an allowlist that starts empty. Codex has three sandbox modes: read-only, workspace-write and danger-full-access, the last of which “removes the filesystem and network boundaries.” Both tools warn about bypass modes. Claude Code says to use bypassPermissions only “in isolated environments like containers or VMs,” and the Codex CLI (version 0.162.0) describes its bypass flag as “EXTREMELY DANGEROUS” and intended for environments that are already sandboxed.

For an agent run you control end to end, a locked-down container is a sensible default. Each flag is documented in the docker run reference:

docker run --rm \
  --network none \
  --read-only --tmpfs /tmp \
  --cap-drop ALL \
  --security-opt no-new-privileges \
  --pids-limit 256 --memory 2g --cpus 2 \
  --user "$(id -u):$(id -g)" \
  -v "$PWD":/workspace -w /workspace \
  your-agent-image your-agent-command

With an Alpine test image and a probe script in place of the agent, the container reported:

interfaces: lo
outbound: blocked
touch: /etc/agent-test: Read-only file system
/tmp writable
/workspace writable
CapEff:	0000000000000000
NoNewPrivs:	1

The none network driver leaves only the loopback interface, so nothing inside can download packages or reach an API. Most agents need to call their model, so a real deployment usually replaces --network none with a network that only reaches an allowlisting proxy. Mount only the project directory, and never mount your home directory, cloud credentials or SSH keys “just in case.”

On a workstation, Claude Code’s documented settings can combine permission rules and the sandbox. This project-level example blocks .env and a secrets folder for Claude’s file tools, stops sandboxed commands from reading the home directory outside the project, and allows two package hosts:

{
  "permissions": {
    "deny": ["Read(./.env)", "Read(./secrets/**)"]
  },
  "sandbox": {
    "enabled": true,
    "filesystem": { "denyRead": ["~/"], "allowRead": ["."] },
    "network": { "allowedDomains": ["github.com", "*.npmjs.org"] }
  }
}

Claude Code evaluates rules in the order deny, ask, allow, so an allow rule cannot carve an exception out of a deny rule.

Secret leakage: keep credentials out of reach

Agents leak secrets in a few predictable ways. A .env or credentials file is read into the context, a command prints an environment variable, generated code hardcodes a key, or a manipulated agent sends a token to an outside address. Once a secret is in the context, it can reappear in a commit, a pull request description, a log or a tool call.

The controls, in order of value:

  1. Make secrets unreachable. Add deny rules for .env files and secret folders, block sandbox reads of credential directories, and start agent processes with a minimal environment.
  2. Give the agent its own short-lived credentials. Scope them to the task and repository. The MCP authorization spec tells local (stdio) servers to take credentials from the environment, and it requires remote servers to accept only tokens issued for them. One leaked token then opens one thing.
  3. Scan before code leaves the machine. Gitleaks runs as a pre-commit hook and exits with code 1 when it finds a leak. With a synthetic GitHub-style token staged in a test repository, gitleaks git --pre-commit --staged --redact reported one finding under the github-pat rule and exited with code 1, which blocks the commit. On GitHub, push protection is on by default for users pushing to public repositories, but repository-level push protection has to be enabled and only covers supported secret types.
  4. Treat a leaked secret as compromised. Revoke or rotate it first. Deleting the commit afterwards does not remove copies that already exist.

Apply the same caution to online tools: the diff checker runs in your browser, but an AI code reviewer sends what you paste to a model, so remove keys and private code first.

Action boundaries and human approval

Approval prompts work only if they are rare enough to be read. OpenAI’s guide names two triggers for human intervention: exceeding failure thresholds, such as repeated failed attempts, and high-risk actions, such as cancelling orders, authorizing large refunds or making payments. A workable starting policy:

  • Allow without asking: read-only actions inside the workspace.
  • Ask: writes outside the workspace, dependency changes, network access to new hosts, and anything that sends messages or money.
  • Deny: production deletes, credential changes and force-pushes to protected branches, enforced in the target system as well as in the agent’s settings.

Show the reviewer exactly what will run. The MCP specification asks clients to show tool inputs to the user before calling a server, “to avoid malicious or accidental data exfiltration” (tools). For code, keep the pull request as the approval gate. Running AI Agents in Production covers turn limits, budgets and incident response.

Common mistakes

  • Treating instructions as enforcement. Claude Code’s memory docs say CLAUDE.md files are context, “not enforced configuration.” Block actions with hooks, permission rules or the sandbox.
  • Trusting a deny list for programs. A rule that blocks curl does not stop the same request from a Python script. Use network isolation.
  • Running the agent with your personal admin token. It inherits everything you can do.
  • Using bypass mode on a laptop that holds real credentials. Bypass modes are meant for disposable, isolated environments.
  • Leaving egress open “temporarily.” Without egress controls, a successful injection can send data anywhere.
  • Logging everything verbatim. Prompts and tool outputs can contain secrets and personal data, so redact them or restrict who can read the logs.

More FindPicked guides

The other hubs in this series cover MCP in practice, context engineering and memory and running agents in production.

Frequently Asked Questions

Can a system prompt stop prompt injection?

No. A system prompt can make the model more cautious, but injected text arrives through the same channel as legitimate data, and OWASP says it is unclear whether fool-proof prevention exists. Limit what a hijacked agent could do with least privilege, sandboxing, egress controls and approval for high-risk actions.

Is a container enough to sandbox an AI coding agent?

A container with no network, a read-only root filesystem, dropped capabilities and only the project mounted removes much of the easy damage. It still shares the host kernel and is only as strong as its mounts and network rules. Use a VM or a remote environment for untrusted code at scale.

What is the lethal trifecta for AI agents?

It is Simon Willison’s name for an agent that combines access to private data, exposure to untrusted content and the ability to communicate externally. With all three, an attacker can trick the agent into sending private data out. Remove at least one of the three for each session, or add a human check before data leaves.

Which agent actions should require human approval?

Irreversible or high-stakes actions: deleting data, changing credentials or permissions, deploying, sending messages or money, and pushing to protected branches. Keep read-only actions automatic so that approval prompts stay rare enough to be read carefully.