Part 04: Safety and Security#
Threat-model an LLM application or agent, recognize prompt injection and agent-specific attacks, choose defenses and monitoring, and run a red-team exercise.
The reader can build an agent (part 02) and evaluate it (part 03). This part teaches defensive security engineering. It explains the attacker's view only as far as a defender needs it.
Chapters#
| # | Chapter | Level | Read | What you learn to do |
|---|---|---|---|---|
| 01 | Threat Modeling LLM Applications and Agents | Practitioner | 25 min | Write a threat model: assets, attackers, trust boundaries, the CIA goals, and where LLM systems differ from ordinary software |
| 02 | Jailbreaks and Prompt Injection | Practitioner | 25 min | Tell a jailbreak from an injection, explain why instructions and data share one channel, and classify a payload |
| 03 | Agent-Specific Attacks | Practitioner | 25 min | Recognize memory poisoning, retrieval and tool poisoning, environment injection, propagation, and excessive agency |
| 04 | Defenses: Guardrails, Detection and Secure Design | Practitioner | 30 min | Assemble a defense in depth, from input filters to privilege separation and human approval gates |
| 05 | Runtime Monitoring and Detection | Professional | 20 min | Place runtime protections in an architecture and state their cost, latency, and false-positive trade-offs |
| 06 | Red-Teaming and Safety Evaluation | Practitioner | 25 min | Run a red-team exercise, build an adversarial data set, measure the attack success rate, and gate regressions in CI |
| 07 | Trustworthiness Beyond Injection | Practitioner | 25 min | Test for privacy leakage, stereotyping, and unequal decisions, and explain representation engineering |
| 08 | AI for Cyber Defense and Vulnerability Detection | Practitioner | 25 min | Explain how agents find vulnerabilities with interactive tools, and what that changes for defenders |
| 09 | Policy, Governance and Standards | Professional | 20 min | Write a marginal-risk assessment, a rollout policy, and place the standards landscape with dates |
Before you start#
You need no machine learning background. Read these three chapters first if you have not:
- The Anatomy of an Agent, for tools, memory, and the agent loop.
- A Minimal Evaluation Harness, because every defense in this part is judged by a measurement.
- Tool Design and Function Calling, because most attacks in an agent end in a tool call.
Two ways through#
- In order, 01 to 09. Each chapter assumes the one before. The core line is 01, 02, 03, 04, 05, 06.
- By problem. Attacked already: start with 01 and 06. Reviewing a design: 01, 03, and 04. Asked about compliance: 09, then 07. Shipping a coding or security agent: 08, then 03.
What you build#
Each chapter ends with an exercise with a deliverable. By the end of the part you have:
- A one-page threat model of an agent.
- A harmless injection suite with a canary oracle.
- An exposure map of the agent's stores, sources, tools, and neighbors.
- A policy gate on tool calls, with the attack success rate and the utility before and after it.
- An audit trail and an out-of-band monitor with three rules.
- A versioned adversarial data set and a CI gate.
- A trustworthiness report with benign and adversarial results.
- A small finding loop for memory-safety bugs, in a sandbox.
- A marginal-risk assessment and a one-page rollout policy.
All demonstration payloads in this part are canaries: harmless words that prove a mechanism. Run them only on systems you own or have written permission to test.
Sources and dates#
- Dawn Song gave the backbone in three Berkeley lectures: Fall 2024 (trustworthiness and policy), Spring 2025 (agentic AI safety and security), and Fall 2025 (agentic AI safety and security, with automatic red teaming and runtime defenses). Chapters attribute each claim to its lecture and timestamp, and the first chapter shows how her frame grew across the three terms.
- Charles Sutton (Google DeepMind) gave the lecture behind chapter 8 (Spring 2025).
- Community lists were checked on November 24, 2026: the OWASP Top 10 for LLM Applications 2025 and the OWASP Top 10 for Agentic Applications 2026.
- Laws, standards, and products change faster than a course. Each dated claim carries its date. Check the current text before you rely on one.
Two topics belong to other parts, which this part links to rather than repeats:
- General security and privacy of ML systems: Security, Privacy, Transparency and Accountability.
- Capability and risk evaluation: Evaluating Capabilities and Risks.
Lecture guides for this part#
Each guide maps one lecture from its first minute to its last and says where this book teaches each piece. Where no chapter teaches a part of the lecture, the guide explains it itself; the table counts those parts.
| Lecture | Lecturer | Length | Parts no chapter teaches | Guide |
|---|---|---|---|---|
| Agentic AI Safety & Security | Dawn Song (UC Berkeley) | 1:50:00 | 3 of 10 | open guide |
| Towards building safe and secure agentic AI | Dawn Song (UC Berkeley) | 1:52:00 | 2 of 10 | open guide |
| Towards Building Safe & Trustworthy AI Agents and A Path for Science- and Evidence-based AI Policy | Dawn Song (UC Berkeley) | 1:46:00 | 3 of 19 | open guide |
| Coding Agents and AI for Vulnerability Detection | Charles Sutton (Google DeepMind) | 1:28:00 | 5 of 20 | open guide |
Where to go next#
- The capstone builds a monitoring agent for prompt injection: Capstone: Monitoring Agent for Prompt Injection.
- Berkeley's course project, in which a green agent prepares tasks and assesses white participant agents, is documented in the case study.