Skip to content

Chapter 7 of 8

Safety, Alignment, and Security

As agents gain autonomy and tool access, safety becomes paramount. Guardrailing implements safety checks, input and output filters, and constraints to prevent agents from taking harmful or unintended actions. Stop conditions provide predefined criteria — task completed, max iterations reached, error threshold exceeded — that tell the agent when to stop iterating. The human-in-the-loop pattern requires human approval for certain decisions, balancing autonomy with safety, while the ask-before-acting pattern has the agent explain planned actions and wait for user confirmation. Progressive autonomy gradually increases an agent's freedom as trust is established, and confidence thresholds restrict autonomous action to cases where the agent's certainty exceeds a defined level.

The principle of least privilege dictates that agents should receive only the minimum permissions and tool access needed for their specific task, reducing risk of misuse. Sandboxing runs agents in isolated environments to limit damage from unexpected behavior, while capability control limits abilities like internet access or file deletion. The reversibility principle favors actions that can be undone when mistakes occur, and a kill switch provides immediate halt capability. Defense in depth layers multiple security measures — input validation, output filtering, sandboxing, monitoring — so that no single failure compromises safety. Structured agent output validation checks outputs against expected JSON schemas before processing.

Several well-known threats target agents. Prompt injection tricks the agent into ignoring its instructions, while indirect prompt injection embeds malicious instructions in external data sources the agent reads. The confused deputy problem arises when an agent with elevated permissions is manipulated into performing actions that benefit an attacker. Tool poisoning injects malicious instructions into tool descriptions or MCP server responses. Data exfiltration risk concerns agents being tricked into sending sensitive data to external endpoints. The OWASP Top 10 for LLM Applications catalogs these vulnerabilities, with excessive agency — granting agents too many capabilities, too much autonomy, or too many permissions — being a central concern. Defenses include input sanitization, instruction hierarchy enforcement, output filtering, separated data from instructions, and red-teaming to systematically discover vulnerabilities. Alignment research addresses deeper concerns: ensuring agents faithfully serve human interests (the principal-agent problem), remaining corrigible so they can be safely shut down, and avoiding specification gaming where they satisfy literal requirements while violating the intended spirit.

All chapters
  1. 1Foundations of AI Agents
  2. 2Reasoning, Planning, and Tool Use
  3. 3Agent Memory and Knowledge
  4. 4Multi-Agent Systems and Inter-Agent Protocols
  5. 5Frameworks for Building Agents
  6. 6GitHub Copilot and AI Coding Tools
  7. 7Safety, Alignment, and Security
  8. 8Evaluation, Benchmarking, and Production Operations

Drill it

Reading is not remembering. These come from the AI Agents deck:

Q

What is a standalone AI agent?

An autonomous software system that perceives its environment, reasons about goals, and takes actions without continuous human intervention.

Q

What are the four core capabilities of an AI agent?

Perception (sensing environment), Reasoning (planning and deciding), Action (executing tasks), and Learning (improving over time).

Q

What distinguishes an AI agent from a simple chatbot?

An AI agent can autonomously plan, use tools, maintain state across interactions, and take multi-step actions, whereas a chatbot typically only responds to indi...

Q

What is the agent loop (observe-think-act)?

A cycle where the agent observes the environment, thinks/reasons about what to do, acts on that decision, then observes the result and repeats.