Part 04›
✎

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:

Two ways through#

What you build#

Each chapter ends with an exercise with a deliverable. By the end of the part you have:

  1. A one-page threat model of an agent.
  2. A harmless injection suite with a canary oracle.
  3. An exposure map of the agent's stores, sources, tools, and neighbors.
  4. A policy gate on tool calls, with the attack success rate and the utility before and after it.
  5. An audit trail and an out-of-band monitor with three rules.
  6. A versioned adversarial data set and a CI gate.
  7. A trustworthiness report with benign and adversarial results.
  8. A small finding loop for memory-safety bugs, in a sandbox.
  9. 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#

Two topics belong to other parts, which this part links to rather than repeats:

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#