Part 04›
✎

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):

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
  1. Browse. The agent asks for main, summarizes it, and follows each identifier it meets.
  2. Hypothesize. It writes a report in plain language: which line has which bug, and what kind of input would trigger it.
  3. Build an input. It writes a Python script that generates the input, instead of writing the input itself.
  4. Run. The debugger runs the whole program. It reports which breakpoints were hit and the values of the requested expressions.
  5. Read the result. If the program did not behave as predicted, the agent revises and tries again.
  6. 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:

What the practitioners say#

What it means for defenders#

This list applies the lectures. It is this repository's judgment.

  1. Run variant analysis after every fix. Ask an agent for bugs of the same class in the same project.
  2. 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.
  3. Keep the person at the end. Exploitability and priority need a judgment.
  4. Sandbox the agent. It runs attacker-like inputs and arbitrary commands.

What it means for risk#

Pitfalls#

Try it#

Build the smallest finding loop on your own machine.

  1. Write five small C functions. Plant a memory-safety bug in three of them.
  2. 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.
  3. Ask it to produce an input that makes each program crash under AddressSanitizer.
  4. 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#

Self-check#

  1. Why is a function with no bounds check not necessarily vulnerable?
  2. What is the oracle in Big Sleep, and what tool produces it?
  3. Why does the agent write a Python script instead of the input itself?
  4. What is variant analysis, and when should a team run it?
  5. 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#

Next#

→ Policy, Governance and Standards, for how findings like these enter risk assessments and regulation.