AgentKits

How to Design Safe AI Agents: A Practical Engineering Guide

Safe agent design is mostly subtraction: remove the tools it doesn't need, remove its ability to act irreversibly alone, remove its license to answer when it doesn't know. Here's the full checklist.

There's an uncomfortable truth at the center of agent safety: capability and safety are separate problems, and a more capable model does not give you a safer one. The conversations about AI agents tend to split into breathless enthusiasm or reflexive fear, and both miss the engineering reality, which is calmer and more actionable. A safe agent isn't one that never makes mistakes — that's not achievable — it's one whose mistakes are observable, containable, and recoverable. That reframing, increasingly the consensus among security teams in 2026, is the foundation everything else in this guide is built on.

The stakes are concrete. The OWASP AI Agent Security Top 10 for 2026 names "Excessive Agency" and "Improper Access Control" as top-tier risks — meaning the most common ways agents cause harm aren't exotic exploits but agents simply being allowed to do more than they should. NIST launched its AI Agent Standards Initiative in February 2026 to accelerate work on secure identity and authorization, and the International AI Safety Report 2026, compiled by experts from 30 countries, explicitly called current voluntary commitments insufficient and asked for stronger governance. Regulatory teeth are coming. Teams that build the guardrail infrastructure now will be ahead of it rather than retrofitting under deadline.

Start by defining the worst-case action

Before any code, write down the single most damaging thing your agent could do if it misfired, was manipulated, or was compromised. This is the worst-case action, and it's the most useful sentence in the whole design process because it sets the proportionality of everything that follows. An agent whose worst case is "returns an unhelpful answer" can run with light oversight. An agent whose worst case is "issues a refund," "deletes a customer record," or "sends an email to a client" needs hard controls around exactly those actions.

The distinction that makes this practical is between drafting and doing. "Draft an email" is safe; "send an email" is not. "Propose a database change" is safe; "execute the write" is not. A remarkable amount of agent safety comes from splitting every consequential capability into a reversible proposal step the agent owns and an irreversible commit step that's gated. The agent gets to be useful right up to the edge of consequence, and a human or a rule crosses the edge.

Least privilege is the highest-leverage control

The most effective guardrail is limiting what the agent can do in the first place — not instructing it to behave, but scoping its actual permissions so misbehavior is impossible rather than merely discouraged. Least privilege for agents means task-specific and time-bounded access: if an agent reads a database for a reporting task, it should not also have write access to that database, or any access at all once the task is done. A customer-service agent does not need write access to billing. Database access should be read-only where possible; write permissions scoped to specific tables; API access limited to the exact endpoints the task requires.

This is where agent identity becomes a design requirement, not an afterthought. Each agent should carry its own non-human identity with scoped, time-limited credentials, enforced through your existing IAM (Okta, Azure AD, or equivalent), so that permissions are real infrastructure rather than promises. The payoff is that an over-reach becomes structurally impossible, and when something does go wrong, the action is attributable to one agent you can revoke without breaking the rest.

Enforce guardrails outside the model

Here's the failure that catches teams who write careful prompts: most guardrails are socially enforced rather than cryptographically enforced. When you tell an agent "stay within this folder" or "don't touch these resources," you're relying on the model's compliance with an instruction — and the line between instruction and data is fundamentally blurry in language models, which is exactly why prompt injection works. An attacker who can get text in front of your agent can often talk it past a prompt-level rule.

The fix is to enforce the rules where the model can't argue with them: in the orchestration layer or a policy engine, outside the model entirely. A guardrail that lives in code remains reliable even when the model is confused, manipulated, or explicitly instructed to bypass it. A well-written instruction won't matter if the agent can still click "send" or write into a system with broad permissions — so the rule has to live in the tool layer, where "send email" simply isn't an available action unless conditions are met. The honest framing, from one engineer who's lived it: don't pretend you can build a perfect safeguard; layer mitigations and make informed decisions about residual risk.

Layer the defenses, because no single one holds

The pattern security teams and regulators converge on is defense-in-depth: stack multiple independent guardrail layers so that if one fails, another catches the problem. OWASP recommends exactly this for prompt injection, because no single control is reliable alone. In practice that's five layers. Input guards screen what comes into the agent. Tool and action gating scopes which tools the agent can use at all — least privilege as a setting. Output guards check what the agent produces before it's acted on. Human approval gates the high-risk actions. And evaluations close the loop as continuous feedback. Each layer is imperfect; the stack is resilient.

Design human oversight so it actually works

Human-in-the-loop is the most cited guardrail and the most often botched. A system that sends 500 approval notifications a day is worse than no system at all — it manufactures alert fatigue, and the human degrades into a rubber stamp who clicks approve without reading. Oversight that nobody can sustain isn't oversight; it's theater that produces an audit trail of unexamined approvals.

Effective human oversight is tiered. Pre-action approvals gate the genuinely irreversible or material decisions — payments, deletions, external communications. Post-action reviews sample lower-risk actions for quality and learning without blocking them. Conditional approvals combine rule-based thresholds with human review, so a refund under $50 proceeds automatically while one over $500 routes to a person. The goal is to spend scarce human attention only where the worst-case action lives, and to train the reviewers for informed judgment rather than blind approval — teach them what to look for, how to evaluate, and when to reject.

Verify trajectories, not just outputs

An agent is a control loop — it plans, acts with tools, observes, updates state, and repeats until it reaches a goal or hits a budget. That means a safe agent has to be evaluated on the whole trajectory, not just the final message. Did it choose the right tool? Were the arguments valid? How many steps did it take, and at what time and cost? Did it stay within policy at every hop? An agent can produce a correct-looking final answer through an unsafe path — accessing data it shouldn't have, or looping expensively — and output-only checks miss it entirely.

Build deterministic verification wherever you can: automated tests, validation harnesses, and regression checks that make correctness verifiable without a human in the loop for every output. Add automated circuit breakers that trip on anomalies — unusual volume, out-of-scope access, output-quality degradation — so a misbehaving agent is contained automatically rather than after someone notices. And log everything: prompts, tool calls, decisions, approvals, and failures. The log is what makes a mistake recoverable and an audit answerable.

The shape of a safe agent

Put together, a safe agent has a known worst-case action, the minimum permissions to do its job and no more, guardrails enforced in code rather than requested in prose, several independent layers of defense, human approval placed precisely where consequence lives, and complete trajectory-level observability. None of this makes the agent less capable — it makes it predictable, which is the actual precondition for letting it do anything that counts. The reframing that started this guide is also how it ends: you are not trying to build an agent that never errs. You're building one whose errors you can see, stop, and undo. That's the difference between a demo and a system you can deploy.

Frequently asked questions

Keep reading

← All posts