Lecture guides›
✎

Lecture guide: Coding Agents and AI for Vulnerability Detection#

Lecturer: Charles Sutton (Google DeepMind) · Course: UC Berkeley Advanced LLM Agents MOOC, Spring 2025 (CS 194/294-199), lecture 5 · Length: 1:28:00 Video: watch on YouTube · Slides: slides Chapters that cite this lecture: 08. AI for Cyber Defense and Vulnerability Detection

In one sentence: Charles Sutton explains coding agents through their evaluations and their design choices (SWE-agent, Agentless and others), then shows why a model that only reads code is a poor way to find security vulnerabilities, and how an agent with a debugger and a sanitizer, Big Sleep, found a real bug.

Before you watch#

The chapter AI for Cyber Defense and Vulnerability Detection covers the last third of the lecture, and Coding Agents covers the middle from another lecturer's angle. Sutton speaks to students who have already seen agent loops. Sutton says his own background is far more in deep learning than in computer security, and he explains the security terms he relies on, such as sanitizers and fuzzing.

The lecture, part by part#

0:00–3:59 Introduction#

Charles Sutton introduces himself as a machine-learning researcher who came to security late: a postdoc at Berkeley with Michael Jordan, a doctorate in machine learning for language before deep learning existed, a professorship at Edinburgh working on program synthesis, and Google since 2018 on code generation. His two pieces of career advice: change is normal, so learn to change with the technologies; and look across disciplines, because understanding the problem a technology serves makes the technical work better. The talk has three parts: coding agents, AI for security, and a project on finding security bugs. In this book: not needed (lecture introduction).

3:59–7:47 What an agent is, without the buzzword#

Stripped of the buzzword, an LLM agent is a multi-turn language model that uses tools, and the heart of it is the loop the ReAct paper described. The lecturer gives four reasons why this matters. The model gains computation time, since a thought before an answer avoids committing to the first tokens. Tools bring information from outside: in coding, run the code and write the next version from what happened. Tools let the agent test hypotheses, say that the code will break at line 13, run it, and revise. And a tool is how the agent touches the external world at all. He treats planning and chain of thought as uses of the extra computation, and calls multi-agent designs still unproven. In this book: AI for Cyber Defense and Vulnerability Detection › The core idea.

7:47–13:30 The first code evaluations and pass@k#

Before agents, the lecturer covers evaluation, because the evaluation drives what gets built. Around 2021, when OpenAI's Codex appeared, MBPP and HumanEval tested natural-language-to-code generation: a few hundred problems, each a short Python function of five to ten lines written from a one- or two-sentence description and checked by assertions, all written by people. The score is pass@k, the share of problems where at least one of k samples passes; Sutton no longer recommends these sets, which are to code what MNIST is to vision. Three points survive: have an automated correctness check; choose k to measure the diversity of the model's answers; and ask whether the metric matches deployment, since nobody wants ten completions to choose from, though a pipeline may keep the samples that pass tests. A statistical aside: to estimate pass@10, do not derive it from the success rate of 100 samples; draw subsets of 10 without replacement and count how often one contains a success. In this book: A Minimal Evaluation Harness › 5. Compute the metrics.

13:30–20:30 SWE-bench: a step up, with known flaws#

Those sets worked in 2021 because they were just hard enough (neither at the floor nor at the ceiling) and not yet leaked; now they are easy and certainly in the training data. The most influential evaluation for agents is SWE-bench: real problems collected from Python repositories on GitHub, where the task statement is the text of an issue, and each case has a patch and tests that failed before the patch and pass after it; the goal is to produce the patch from the issue. Its virtues are timing and realism: base models scored 2 to 3% when it appeared, so it could drive development, and agents then gave a clear jump. Its flaws: the twelve projects cover a narrow set of domains; issue texts are sometimes underspecified or tangled with unrelated tests, which a filtered subset removes; a patch can pass the tests without being correct; the language of an issue differs from what a person types in an editor; some issues hint at the fix; leakage becomes a concern once scores reach 50%; and many commits mix the fix with other changes, which also spoils patches used for fine-tuning. In this book: Coding Agents › How coding agents are evaluated.

20:30–22:34 The evaluation decides what gets built#

Sutton has gone through the evaluations at length to draw one lesson: the quality of a model or an agent is driven in large part by the quality of its evaluation. An organization that builds them is doing a huge combinatorial search over knobs (tools, system instructions, the post-training mixture), so weak numbers mean climbing the wrong hill. A good evaluation sits at the right difficulty, is realistic, tests what you care about and is not leaked, and every evaluation has a shelf life, so new ones must keep coming. In this book: Evaluation Is the Product › The core idea · AI for Cyber Defense and Vulnerability Detection › Pitfalls.

22:34–26:00 SWE-agent's loop#

SWE-agent was an early agent built for SWE-bench-style tasks, and a milestone. It combines three known ingredients: the model explains what it will do before acting, the tools are specific to software development, and the agent gets execution feedback. The loop is simple: a trajectory of text grows as, at each step, the model writes more text ending in a tool call; the tool, roughly a Python function that returns text, runs; its output is appended; and the step repeats, with a system instruction asking the model to explain itself. One option is to hand the agent a Linux shell and an IDE, which still felt ambitious; the lecturer's theme is that the harness and tools must be designed together with what the model can do, in formats close to its post-training data. In this book: The Anatomy of an Agent › The core idea.

26:00–30:00 Designing tools for a model: the agent-computer interface#

The alternative is a small number of tools with inputs and outputs friendly to the agent, which the SWE-agent paper calls an agent-computer interface, by analogy with a user interface. Its principles: tools should be easy to describe, without invented vocabulary (he cites the Little Red Riding Hood principle from the Copilot team: lead the model down familiar paths, for instance with a command to jump to a line); actions should be compact, not four or five calls for one logical step; outputs need design (trailing newlines, how to summarize long outputs); and state needs guardrails, since a syntax error the agent does not notice ruins the rest of the trajectory. In this book: Coding Agents › The agent-computer interface.

30:00–36:26 SWE-agent's tools and results#

A Linux shell was included but rarely helps. The useful tools fall into three kinds: gathering information (search for a term in a file or a directory; open a file and scroll when it is too long for the context), acting (edit or create files), and submitting. A guardrail rolls back an edit that breaks the syntax or the linter, and tools fit together, for instance when a search returns line numbers for the next command. The model usually searches identifiers from the issue, edits, then submits, though nothing forces that order. On the two thousand or so issues, base models resolved 1 to 3%; Sutton had thought the set useless because nothing could climb from there, but an agent loop reached about 12%, and the state of the art has since gone much higher. His criticism of such comparisons: agents spend more tokens, so report the cost per success and compare at equal compute, because a tool that helps may only be adding tokens to the trajectory. In this book: Coding Agents › 2. Action space · Coding Agents › Pitfalls.

36:26–40:00 Agentless: the procedural extreme#

Agentless sits at the other end of how much control flow a person writes. The logic is ordinary Python code for program repair, and the model is called wherever the algorithm needs judgment. Three steps: decide what to edit, generate a patch, validate it. Localization is hierarchical: the repository's structure yields a list of likely files, skeletons of their classes and methods narrow it to places, then to lines, each step keeping an n-best list. For every candidate a model writes a patch independently. Since the hidden tests are unknown, the agent must write its own tests for the issue, run them, keep the patches that pass, rank them and submit one. In this book: Coding Agents › 5. A checker · Coding Agents › 3. Context.

40:00–43:34 Comparing the two designs#

The choice is about budgeting test-time compute. In a dynamic agent the model picks its own problem-solving strategy: after a failing test it may search more or make a small change. In a procedural one, if a simple workflow solves the task, there is no reason to make the model discover the workflow; tool use happens around the model rather than inside it, so there are fewer tool errors, and an early mistake cannot derail a whole trajectory. The question for a failed patch is whether to extend it or to generate a new one: Agentless generates and tests, a dynamic agent can choose. Sutton guesses that generate-and-test suits small patches and flexibility will win for long, complex changes; shell-only, SWE-agent and Agentless form a continuum whose best point shifts with model capability and task complexity. In this book: nothing beyond this guide; nearest: Coding Agents › 2. Action space.

43:34–48:00 AutoCodeRover and RepairAgent: two more points on the continuum#

AutoCodeRover, from a team at a university in Singapore, changes two things. Its search tools index classes and methods the way an IDE does, so the agent can find a class by name or a method in a class. Its control loop is two dynamic agents run in sequence, one to retrieve context and one to write the patch, each with its own system instruction and tools; that gives some procedural structure and information hiding, since only the result of the first loop passes to the second. RepairAgent goes further: the agent's design is a state machine for investigating and fixing a bug. Each state has its own system instruction, and the model's next tool call decides the transition: a code search keeps it in the information-gathering state, a call to write a fix moves it elsewhere. In this book: nothing beyond this guide; nearest: Coding Agents › 2. Action space.

48:00–55:23 An industrial agent, and the design space#

Industrial coding agents get little technical publicity, so Sutton describes one he knows from inside: a research agent at Google that fixes internal issues in a monorepo so large that no laptop holds it. Its evaluation was built like SWE-bench from internal bugs and fixes, filtered by heuristics such as a change in tests and the size of the patch; one subset has bug reports written by people, another has reports filed automatically by sanitizers, dynamic analysers that crash a program on an out-of-bounds access. The agent is SWE-agent-like with Google's own tools (code search, the build system, file viewing and editing), and its tasks differ from SWE-bench: human-written patches are larger and touch more files. He closes the first half by listing the design space all these agents share: which tools, who writes the control flow (dynamic, state machine, recursive sub-agents, plain code), the wording of instructions and tool descriptions, sandboxes for model-generated code, contact with external services, and when to ask a human. In this book: nothing beyond this guide; nearest: Coding Agents › How coding agents are evaluated.

55:23–62:30 Security as capture the flag, and EnIGMA#

For AI in security the lecturer starts from capture-the-flag competitions, toy versions of professional tasks in which a hidden string, the flag, proves success: digital forensics (a hidden message in a file system), cryptography, exploiting memory bugs, and web attacks such as injection. They map onto real work, an agent obviously suits them, and datasets of past competitions exist with a task description, a sandbox and an automatic checker. EnIGMA adapts the SWE-agent toolset to them: the usual file tools and command line, plus stateful tools for a debugger (start, stop, step) and for connections to servers, long outputs summarized by a model, and system-instruction bullets added whenever a reading of the trajectories reveals a mistake. Scores rose from 3 to 4% without an agent to double digits with one. In this book: AI for Cyber Defense and Vulnerability Detection › Capture the flag · Evaluating Agents: Trajectories and Environments › 7. Read the trajectories and sort the failures.

62:30–66:00 What a vulnerability looks like#

A vulnerability is a bug with security consequences; the lecture sticks to software, where most work has been done, with examples such as out-of-bounds reads and cross-site scripting. A taxonomy of software bugs shows a short case of an out-of-bounds write: a function returns minus one on error, the caller uses it as an index, the value converts to an unsigned number and the write lands far from the array. The second example is real, from the Linux kernel: a function copies data out of an incoming network message, allocating a buffer with a size taken from the header and then copying the payload into it, without checking that the two agree. In this book: AI for Cyber Defense and Vulnerability Detection › The core idea.

66:00–68:00 Why finding them is hard#

Two things make detection hard. Many functions look alike and are perfectly safe, so the search is for a needle in a haystack, and inputs that reach a given function are hard to craft. And a single function is neither vulnerable nor safe; if the caller checked the size, it is fine, so the question only makes sense globally. In this book: AI for Cyber Defense and Vulnerability Detection › The core idea.

68:00–70:09 Why the obvious datasets disappoint#

This undercuts the obvious data source. Public vulnerabilities get an identifier, a description and a link to the fix in public databases, thousands of them, so the natural move is to download them and train a classifier for vulnerable code, as many papers did. Sutton, who would have done the same, calls the problems fundamental: how much code to include; the notion of a vulnerable line or function is not meaningful when the fault sits upstream of the line that crashes; how much context to give; commits that mix the fix with other changes; and judging a patch statically, since there are many correct patches and the descriptions are vague and noisy. His advice is a dynamic evaluation instead, one that runs the code on an input exposing the bug. In this book: nothing beyond this guide; nearest: AI for Cyber Defense and Vulnerability Detection › The core idea.

70:09–74:00 Fuzzing, static analysis and dynamic datasets#

Dynamic sets exist: a DARPA-sponsored competition on AI for vulnerability detection (with an older one from 2016), a security evaluation from Meta that includes memory vulnerabilities, and ARVO, which packages vulnerabilities once found by fuzzers so that they can be run. Fuzzing itself, running a program on many random or mutated inputs, is the most common automatic technique and is used heavily on security-critical software, but it plateaus: famous bugs were exploited in much-fuzzed code the fuzzer could not reach, which leaves room for AI to find deeper bugs. Static analysis suffers from combinatorial explosion and false positives. In this book: AI for Cyber Defense and Vulnerability Detection › The core idea.

74:00–80:00 Big Sleep: an agent that behaves like an auditor#

Big Sleep, named after a 1940s film, is a collaboration between Google DeepMind and Google's Project Zero, a team that finds vulnerabilities in open-source projects. Its premise comes from watching human auditors: they do not label code vulnerable or not after reading it; they form a hypothesis and test it in a debugger. So the agent gets a code browser and a debugger, which is dynamic analysis, unlike a model that only reads. It targets memory-safety bugs and acts like a fuzzer with reasoning: produce an input that makes the program misbehave. Unlike code editing, the task has an oracle: the program runs under a sanitizer and a debugger, and a crash means a bug was found. The tools are an indexed code browser (jump to a definition, follow cross-references), a Python program the agent writes to generate the input, and a debugger that runs the whole program without interaction; the agent names breakpoints with optional expressions, really watchpoints, and afterwards learns which were hit and the values. In this book: AI for Cyber Defense and Vulnerability Detection › The Big Sleep loop.

80:00–86:00 A trajectory, and variant analysis#

In an example from Meta's benchmark, the agent asks for the main function, summarizes what it sees, follows identifiers through several turns of browsing, then writes a report: a string copy without bounds checking, which it calls a classic buffer overflow. It writes a Python program for the input, which can build long or binary strings, and asks for values along the suspected path. The program exits without crashing; the agent notes that it failed earlier than expected, updates the input and tries again until the program crashes. It is reasonably effective on such benchmarks, with much to do on scaling, and it has found one real-world vulnerability, in SQLite. That came from variant analysis, since a fixed bug often has similar variants elsewhere and many bugs exploited in the wild are variants of fixed ones: given a recently fixed SQLite bug, the agent found a similar one, a favourable case because the model has seen many SQL queries. A state-of-the-art fuzzer then failed to find that bug in 150 hours. In this book: AI for Cyber Defense and Vulnerability Detection › The Big Sleep loop · AI for Cyber Defense and Vulnerability Detection › Variant analysis.

86:00–1:28:00 Summary#

Sutton sums up security as a wide-open area where agentic techniques fit naturally, because the work means interacting with servers and running debuggers. It is also a test bed for code understanding: finding a bug means thinking about corner cases the developer did not consider and following data flows, sometimes across several interacting programs. He calls it an exciting time to enter the area, now that such agents are starting to be scaled up, and then opens the floor to further questions. In this book: nothing beyond this guide; nearest: AI for Cyber Defense and Vulnerability Detection › What it means for defenders.

What to take away#

Sources#