Agentic Engineering from First Principles All chaptersLecturesLabDownload the book
Part V · Engineering Reliable Agents

Chapter 26: Security

Central questionHow do we prevent untrusted information from becoming trusted control, when agents can read external content, remember it, call tools, write state, and take actions?

Lecture

Chapter principle

Keep authority outside untrusted content. Treat external text, retrieved evidence, memory, tool output, remote-agent artifacts and generated code as inputs with provenance. Let software-enforced identity, permissions, approvals, schemas, budgets and sandboxes determine what authority those inputs can ultimately exercise.

Key takeaways

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

This is Chapter 26 of Agentic Engineering from First Principles: thirty chapters, a case study and fifty-nine executable experiments, from a single model call to controlled, self-improving agents.
Download the bookBrowse all chapters
← Chapter 25: Human-in-the-LoopChapter 27: Budgets and Stopping →