08. AI for Cyber Defense and Vulnerability Detection#
Level: Practitioner · Reading time: 25 min · Exercise: 60 min Prerequisites: Tool Design and Function Calling
In one sentence: After this chapter you can explain how an agent finds a memory-safety bug with a code browser, a scripting tool, and a debugger, why a sanitizer makes the result trustworthy, and what it changes for a team that ships and patches software.
Why this matters#
Your issue tracker holds two thousand sanitizer reports. A library you depend on publishes a security fix. The same mistake probably sits in three other places in your code, and nobody has time to look.
The question of this chapter: can an agent do the work of a security researcher on your code, and what changes when attackers have the same agent?
The core idea#
A software vulnerability is a bug with security consequences. Charles Sutton, who is part of the Big Sleep team at Google DeepMind, gives the examples of out-of-bounds reads and writes and cross-site scripting (62:00, Spring 2025).
Reading code is a poor way to find them. His reasons (66:00, Spring 2025):
- There are many functions that look similar and are perfectly safe. It is a needle in a haystack.
- One function is not vulnerable or safe on its own. If the caller checked the size, the function is fine.
His answer is to let the model act, not only read. A sanitizer is a tool that adds checks to a running program and crashes it when it does something forbidden, such as writing past the end of a buffer. So there is a test with two outcomes: an input crashes the program under the sanitizer, or it does not. Sutton's summary at 76:00: "we have an Oracle".
Naptime, later called Big Sleep, is Google Project Zero's project built on that idea. Its goal, on Sutton's slide, is to "find vulnerabilities with language models that can think and act like a security researcher".
The analogy is a fuzzer, a program that feeds a target millions of random or mutated inputs and waits for a crash. Big Sleep is a fuzzer guided by reasoning. The analogy breaks on volume. A fuzzer needs no understanding and runs cheaply a million times. The agent runs a few dozen informed experiments per bug.
Sutton's definition of an agent fits the job (4:00): a multi-turn model with tool use, which gains time to think, information from outside, and the ability to test hypotheses by acting.
How it works, step by step#
The Big Sleep loop#
The goal is one input that makes the target crash under a sanitizer. The agent has three tools (slide "Big Sleep design"; 78:00).
| Tool | What it does | Why the agent needs it |
|---|---|---|
| Code browser | Jump to a definition, follow cross-references | Navigate a code base the way an IDE does |
| Python interpreter | Run a script that builds the input | Forty bytes of padding are shorter to write as code than to type |
| Debugger | Run the target with breakpoints and expressions | Check what the program did with the input |
- Browse. The agent asks for
main, summarizes it, and follows each identifier it meets. - Hypothesize. It writes a report in plain language: which line has which bug, and what kind of input would trigger it.
- Build an input. It writes a Python script that generates the input, instead of writing the input itself.
- Run. The debugger runs the whole program. It reports which breakpoints were hit and the values of the requested expressions.
- Read the result. If the program did not behave as predicted, the agent revises and tries again.
- Confirm with a person. A sanitizer crash proves a bug. Whether it is exploitable, and how urgent it is, stays a human decision. That last step is an addition of this repository, and standard practice in security teams.
Figure 1. The Big Sleep loop: each run under the sanitizer either confirms the hypothesis or tells the agent what to change.
flowchart LR
B["Browse the code"] --> H["Hypothesis: which line, which input"]
H --> S["Python script builds the input"]
S --> R["Run under the sanitizer in the debugger"]
R -->|"no crash"| X["Read the result and revise"]
X --> S
R -->|"sanitizer crash"| C["Report with the crashing input"]
C --> P["Person judges exploitability"]
The branch is the point of the design. Without a run there is no signal, and the agent would be guessing like a reader of code.
In Sutton's example trajectory, the first attempt disappointed the agent: the program exited without crashing, because it failed earlier than the agent had expected. The agent wrote down why, updated the input, and ran the debugger again. At some point the program crashed, with an AddressSanitizer report for a heap buffer overflow (80:00, 82:00; the report is on his slide).
Variant analysis#
A variant is a bug similar to one already found, in another place in the same project. Sutton's team put the description of a recently fixed SQLite bug into the context and asked the agent to find something similar. It found one (84:00). This is the method to copy after every security fix you apply.
Capture the flag#
A capture the flag competition is a security contest with small problems to solve. Sutton showed a coding agent adapted for it, with a debugger and server tools (EnIGMA). One design detail matters for any agent that runs commands: the command-line tool runs in a sandbox (slide 39).
Worked example#
A bug small enough to plant, and the two commands that prove it.
/* overflow.c: a bug an agent should find.
Build: cc -g -fsanitize=address overflow.c */
#include <stdio.h>
#include <string.h>
void test_case(const char *content) {
char buffer1[32];
char buffer2[32];
strcpy(buffer2, "BBBB");
strcpy(buffer1, content); /* no bounds check */
printf("buffer2: %s\n", buffer2);
}
int main(int argc, char **argv) {
char input[256];
if (fgets(input, sizeof input, stdin))
test_case(input);
return 0;
}
# make_input.py: what an agent writes instead of typing the padding by hand.
print("A" * 40, end="") # 40 bytes into a buffer of 32
Build with cc -g -fsanitize=address overflow.c, then run python3 make_input.py | ./a.out. What to observe:
- AddressSanitizer stops the program with a stack-buffer-overflow report and the line that caused it. The report is the oracle. Nobody has to judge whether the output "looks wrong".
- The script, not the padding, is the artifact. With a script, the agent can produce binary data, lengths, and checksums the way it did in Sutton's trajectory.
- The agent has an advantage here that a fuzzer lacks. It reads
strcpyon a 32-byte buffer and knows what to try first.
What the practitioners say#
- Results as reported. On Sutton's slide, the agent moved a benchmark result from 0.05 to 1.00 on buffer overflow tasks and from 0.24 to 0.76 on advanced memory corruption on the CyberSecEval 2 benchmark. It found a real vulnerability in SQLite through variant analysis. That bug was hard for general-purpose fuzzers: they did not find it in 150 hours (84:00).
- His caveats. The SQLite case was close to a best case, because the model has seen a great deal of SQL. The work focuses on memory-safety bugs. Network security and red teaming have only started (slide "Summary"; 86:00).
- Look at the trajectories. His advice for anyone who builds agents: read what the agent did, find its mistakes, and add an instruction for each (62:00).
- The lectures connect. In Fall 2024 Dawn Song cited the Project Zero result, a stack buffer underflow in SQLite, as an example of AI finding bugs (78:00). In Fall 2025 she reported her group's own benchmark of close to 200 open-source projects with over 1,500 known vulnerabilities. Agents had to reproduce known bugs with a proof-of-concept input and to look for unknown ones. A recent frontier model found about 28% of the known vulnerabilities with a working input in a single trial (102:00). The lecturer also reports 35 zero-days found, meaning vulnerabilities that were previously unknown, each with a proof-of-concept input. A number of CVEs, public identifiers for known vulnerabilities, have been issued for them, and some are already patched. The model she names is Anthropic's Claude Sonnet 4.5. Her group's answer to the speed of this change is a Frontier AI Cybersecurity Observatory, to keep evaluating agent capabilities continuously (104:00).
What it means for defenders#
This list applies the lectures. It is this repository's judgment.
- Run variant analysis after every fix. Ask an agent for bugs of the same class in the same project.
- Work through the report backlog. A crash oracle is cheap to check, so a sanitizer report is a good unit of work for an agent.
- Keep the person at the end. Exploitability and priority need a judgment.
- Sandbox the agent. It runs attacker-like inputs and arbitrary commands.
What it means for risk#
- Attackers hold the same tools. Song's asymmetry stands: an attacker needs one working bug, and a defender has to fix them all (80:00, Fall 2024). Agents help with work that can be verified, and a crash is verifiable.
- Patch delay matters more. Attackers read public patches and look for variants in systems that have not patched.
- The forecast is hers. In Fall 2024 she stated, as her own belief, that in the near term AI helps attackers more than defenders (94:00).
- Your coding agent is also a target. It reads untrusted repositories and issues, which is the setting of Agent-Specific Attacks.
Pitfalls#
- Asking for bugs by reading alone. Without running the code there is no oracle, and a report is an opinion.
- Trusting a report without a crashing input. The input is the proof. Ask for it.
- No sandbox. The agent runs inputs designed to break programs.
- Fixing one instance. The variant is the bug that gets exploited.
- Testing on patched, public bugs only. Public fixes are probably in the model's training data, so the result flatters the agent. Hold back recent bugs. This follows Sutton's point that every evaluation has a shelf life (20:00).
- Expecting coverage beyond memory safety. Treat other classes as unsolved.
Try it#
Build the smallest finding loop on your own machine.
- Write five small C functions. Plant a memory-safety bug in three of them.
- Give a coding agent three tools: read a file, run Python, and run the built binary. Run everything in a container or a throwaway virtual machine.
- Ask it to produce an input that makes each program crash under AddressSanitizer.
- Record for each program: found or not found, number of steps, and any report without a crashing input.
You are done when you have a table with five rows and those three columns, every "found" has an attached crashing input, and you have counted the reports without proof. Stretch goal: fix one planted bug and ask the agent for variants of it in the other four programs.
Key takeaways#
- Reading code is a weak way to find vulnerabilities. A sanitizer gives a yes-or-no test: the program crashes on an input or it does not.
- Big Sleep gives the model the tools of a security researcher: a code browser, a scripting tool, and a debugger. It hypothesizes in language and tests by running.
- Variant analysis, looking for bugs similar to one that was just fixed, is the method to copy after every security patch.
- Keep a person for exploitability, and a sandbox around the agent.
- Attackers hold the same tools, so fast patching and variant hunting matter more, not less.
Self-check#
- Why is a function with no bounds check not necessarily vulnerable?
- What is the oracle in Big Sleep, and what tool produces it?
- Why does the agent write a Python script instead of the input itself?
- What is variant analysis, and when should a team run it?
- Why do results on old, publicly patched bugs overstate an agent's ability?
Show answers
1. Because a caller may have checked the size. Vulnerability depends on the whole program, not on one function. 2. A crash under a sanitizer, caused by an input the agent built. A sanitizer such as AddressSanitizer produces the report. 3. Because a script is a shorter and more precise way to produce padding, binary data, lengths, and structured input. 4. Searching for bugs similar to one that was just fixed, elsewhere in the same project. A team should run it after applying each security fix. 5. Because the public fix is probably in the model's training data, so the model may recall the bug instead of finding it.Sources#
- Lecture: Charles Sutton, "Coding Agents and AI for Vulnerability Detection", UC Berkeley Advanced LLM Agents MOOC (Spring 2025): video · guide, used at definition of an agent, evaluations have a shelf life, look at the trajectories, why detection is hard, the oracle, tools, SQLite variant
- Lecture: Dawn Song, "Agentic AI Safety & Security", UC Berkeley Agentic AI MOOC (Fall 2025): video · guide, used at cybersecurity benchmark
- Lecture: Dawn Song, "Towards Building Safe & Trustworthy AI Agents and A Path for Science- and Evidence-based AI Policy", UC Berkeley LLM Agents MOOC (Fall 2024): video · guide, used at Project Zero result, asymmetry
- Web: Google Project Zero, "Project Naptime" (June 2024): post, and "From Naptime to Big Sleep" (October 2024): post. Links as given on the lecture slides; not opened for this chapter.
- Reading: Abramovich et al., "EnIGMA: Enhanced Interactive Generative Model Agent for CTF Challenges" (2024), and Bhatt et al., "CyberSecEval 2" (2024), as cited on the lecture slides
Next#
→ Policy, Governance and Standards, for how findings like these enter risk assessments and regulation.