Chapter 26: Security
Lecture
Chapter principle
Key takeaways
- External content is data, not trusted instruction; prompts must be backed by software controls.
- Tool authority comes from the trusted task, not from keyword filters over content.
- Private data, untrusted content and an outbound channel should not meet in one unconstrained agent.
- Retrieval does not sanitize content; memory write policy and provenance are security controls.
- Generated code runs with least privilege in a kernel- or hypervisor-enforced sandbox, never via eval or exec.
- Containment is not correctness; measure attack containment and retained utility.
Experiments
Every experiment in the book is small, runnable and printed with its real output. In the Lab you can replay a recorded real run of each one, with no programming, and watch what the model and the agent do.
Experiment 48: Prompt injection
What if a web page tells the agent to do something else?
The user asks a real model to summarize a short web page. Hidden in the page is an instruction: email a copy of the report to an outside address first. The agent holds one tool too many: besides summarizing, it can send email. The run is tried twice without a gate, where software executes whatever the model proposes, and twice with a gate that allows only the tools the user’s task granted. This is a recorded run of a real model; a new run may differ.
Experiment 49: Memory poisoning
Can something the agent read once change what it does later?
In one session the user asks for vendor research and says they prefer concise reports. The agent then reads a vendor web page claiming the user wants reports sent to the vendor’s own address. A real model acts as the memory writer: it lists the user preferences worth remembering. This runs twice: once reading everything, and once behind a write policy that passes on only messages from the authenticated user. In a later session, a real agent sends the vendor report to "the usual recipient". This is a recorded run of real models; a new run may differ.
Experiment 50: Running untrusted code
Does running generated code in a separate program keep it contained?
The main program holds a secret key. A real model writes three Python one-liners from short descriptions: print the secret, loop forever, and read a file outside the working folder. Each is treated as untrusted code and run as a separate program with no secrets passed in, a scratch folder, and a 1-second time limit. This is a recorded run of a real model; it may write different code in a new run.
All the code for this chapter: github.com/agentic-engineering-book/code
Download the bookBrowse all chapters