esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

How Do Coding Agents Work?

How a coding agent reads your code, edits files, runs tests and proposes a change, and where it can go wrong, explained for your AI interview.

In short

A coding agent is a language model in a loop, with tools. It reads your code, edits files and runs the tests, repeating until the checks pass or a limit stops it. A person reviews the change before it ships.

13 min readIntermediateCommon · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

A coding agent is an AI model that works on your code. You give it a task, and it reads files, makes an edit, runs the tests and reads the output. Then it repeats those steps until the checks pass. A person still reviews the change before it goes live. The loop is simple. What matters is which tools it can use, and the checks that stop it doing damage.

What is a coding agent, in plain words?

A coding agent is an AI model that works inside your codebase, the folder of code a project lives in. You give it a task, such as fixing a bug or adding a field to an API. It reads the code, edits files, runs commands and checks its own work. Then it reports back.

Anthropic's December 2024 guide describes the idea in one line: agents are "typically just LLMs using tools based on environmental feedback in a loop". Here LLM means large language model. Three words carry it: tools, feedback and loop.

Think of a new engineer in their first week. They get a ticket, read the code around it, make a change, run the tests and send it to a senior colleague to review. A coding agent follows the same routine, much faster. It sees only what it is shown, so the setup around it matters.

A real case: a payments team gets the ticket "Refunds on split-card orders come out one cent short." Orders paid with two cards get their refund rounded on each card separately. The agent finds the rounding code, fixes it, runs the 412 tests and opens a pull request. A developer reads the diff and merges it.

Key words

Codebase
All the code, config and tests for one project, usually kept in a repository (repo).
Tool
A function the model can ask for, such as read a file, search, edit or run tests. Your code runs it.
Test suite
The automated checks that confirm the code still does its job. Each one passes or fails.
Pull request
A proposed change that a person reviews before it is merged into the main code.
Sandbox
A fenced-off area where the agent can only touch approved files and servers.

How does the loop work, step by step?

The model never touches your files itself. It only asks. Each turn it reads the task and everything so far, then picks one tool with its inputs. Your side runs the tool and sends the result back. The next turn starts from that result.

One coding agent, one loop

Your task

fix the refund bug in checkout

Model

picks the next step

Tools it can use

Read and search

open files, search the repo

Edit files

change code in the project

Run tests

read the output, do not guess

Pull request

a person reviews the diff

  1. 1Your task starts the loop.
  2. 2The model asks for a tool, such as a file read or a test run.
  3. 3The tool's result goes back to the model, which picks the next step.
  4. 4When the checks pass, the change goes to a person as a pull request.
The model asks for a tool, the tool runs in your project, and its result goes back to the model. The loop stops when the checks pass and the change is ready for review, or when a stop rule trips.
  1. 1

    Read the task

    The model gets the ticket and the project's instructions file, then asks for the files it needs.

  2. 2

    Search and read

    It searches for the rounding code and opens only those files. It can hold just so much text at once, which is its context window.

  3. 3

    Edit

    It proposes a change to the code. You see the change as a diff, the list of lines added and removed.

  4. 4

    Run the checks

    It runs the tests, reads the failures and goes round again if any of them fail.

  5. 5

    Stop

    It stops when the checks pass, or when a limit is reached, such as a maximum number of steps.

  • “During execution, it's crucial for the agents to gain "ground truth" from the environment at each step (such as tool call results or code execution) to assess its progress.”

    Anthropic, on agents

  • “The task often terminates upon completion, but it's also common to include stopping conditions (such as a maximum number of iterations) to maintain control.”

    Anthropic, on stopping

Tip

Name the stop rule in your answer. An agent with no limit can keep retrying the same failing step, so a limit on the number of steps and a spending budget belong in the design.

The run tool is what makes the loop work. Without it, the model has to guess whether its code compiles or its tests pass.

Why do tests decide whether the work is done?

A coding agent can be wrong and still sound sure. Code suits agents well because a test either passes or fails. Anthropic's December 2024 guide says code suits agents for this reason: "Code solutions are verifiable through automated tests", and agents "can iterate on solutions using test results as feedback".

  • Good fix

    The bug is fixed

    The agent finds that the rounding runs on each card. It fixes the total per order instead. All 412 tests pass, and a new test for split orders passes too.

  • Bad fix

    The test is changed

    The agent edits the failing test so it expects the wrong total. Everything goes green and the bug ships. A reviewer who reads the diff would catch it.

Tests check behaviour. They cannot tell whether a change fits the wider system, so a person still reviews it.

How do you keep a coding agent safe?

An agent that can run commands needs limits. In its sandboxing post, Anthropic said Claude Code is read-only by default. It asks before it changes a file or runs a command, with a few exceptions: it auto-allows safe commands such as echo or cat. The same post explains why asking every time is not enough on its own.

Constant approval has a cost. Anthropic warns of approval fatigue, where people may not pay close attention to what they approve. Its answer is a sandbox: fixed boundaries the agent works inside without asking each time. It has two parts, a filesystem limit and a network limit.

Checks between the model and your files

Model's step

a command or an edit it wants

Checks before it runs

Permission rules

allow, ask or deny each tool

Sandbox

limits files and network access

What happens

Blocked

outside the project, or denied

Runs

inside the project and rules

  1. 1The model's step goes through the checks first.
  2. 2A step the permission rules deny is blocked.
  3. 3A step outside the project is blocked by the sandbox.
  4. 4A step that passes both checks runs.
The model's step must pass both checks before it runs: your permission rules and the sandbox. A step the rules deny, or one outside the project, is blocked. The numbered arrows show the path.

The filesystem part lets the agent read and write in the project folder, and blocks changes to files outside it. The network part lets it reach only approved servers. Without the network part, a compromised agent could send out sensitive files. Anthropic says sandboxing reduces permission prompts by 84% in its own internal use.

Here is the gate in plain Python. The model is a fixed script, and the code decides what gets through.

Python
# A simplified coding-agent loop. The "model" is a fixed script, so the run is repeatable.
import posixpath
PROJECT_FILES = ("refunds.py", "tests/")

def allowed(path):
    # Code decides what a tool may touch, not the model.
    return posixpath.normpath(path).startswith(PROJECT_FILES)

def run_tool(name, arg, state):
    if name == "edit" and not allowed(arg):
        return "BLOCKED: " + arg + " is outside the project"
    if name == "edit":
        state["edited"] = True
        return "edited " + arg
    if name == "test":
        return "tests " + ("passed" if state["edited"] else "failed")
    return "read " + arg

script = [("read", "refunds.py"), ("edit", "refunds.py"),
          ("test", "tests/"), ("edit", "/etc/hosts")]

state = {"edited": False}
history = []
for turn, (name, arg) in enumerate(script, start=1):
    result = run_tool(name, arg, state)
    history.append(result)  # the result goes back to the model
    print(turn, result)
print("done after", len(history), "steps")

Output

1 read refunds.py
2 edited refunds.py
3 tests passed
4 BLOCKED: /etc/hosts is outside the project
done after 4 steps

Where do coding agents go wrong?

  • Changing the test, not the code

    It edits a failing test until it passes. Check the diff for any test that changed.

  • Editing outside the task

    It fixes a config file it happened to notice. Limit the tools and scope each task.

  • Missing the file that matters

    On a large repo, the file that holds the bug may never get opened. Give it the entry points and let it search.

  • Fixing the symptom

    The error goes away, but the cause is still there. Read the failing case, not just the green result.

  • Running out of room

    It hits a step limit or the context limit before the work is done. Split the task into smaller ones.

Each of these has the same safety net: a person reads the diff before it merges.

How would you roll a coding agent out to a 40-person team?

Start small and make each step visible. The aim is to make the agent's mistakes cheap and easy to spot.

  1. 1

    Pilot on one service

    Pick a service with good tests and a clear owner. Give the agent read-only access first, so it can look but not change anything.

  2. 2

    Set the limits

    Add a step limit, a spend limit per task and a stop rule before the first run.

  3. 3

    Keep the checks

    Every pull request runs the same automated checks on a server (CI), whoever or whatever wrote it.

  4. 4

    Log every tool call

    Keep a record of what the agent read, edited and ran, so a bad run can be traced.

  5. 5

    Judge by outcomes

    Count changes that merge cleanly and rollbacks, not lines written.

Widen the access only after a few weeks of clean runs, and keep a person on every merge.

What does the interviewer want to hear?

A strong answer covers

  • A plain definition: a language model in a loop, with tools and feedback.
  • The loop: the model picks a tool, the tool runs, the result goes back.
  • Why tests matter: a clear pass or fail gives the agent a signal.
  • The risks: edits outside the task, weakened tests and unchecked commands.
  • Safety: permission rules, a sandbox and a human reviewing the diff.
  • Honest limits: it can be wrong and still sound sure.

Common traps

  • Trap"The agent writes perfect code, so tests are optional."

    BetterTests are what let it check itself. Without them it has to guess.

  • Trap"It runs commands on its own, with no limits."

    BetterIt works inside permission rules and a sandbox, and a person reviews the change.

  • Trap"Coding agents are just autocomplete."

    BetterAutocomplete suggests the next line. An agent picks tools, runs them and acts on the results over many steps.

Can you spot the risk?

Spot the risk

Which agent setup is the riskiest?

Quick check

A coding agent's tests fail after its edit. What should it do next?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q160What is the agent loop?12 min
  2. Q176How should an agent handle tool errors and retries?14 min
  3. Q180How do you sandbox code-running agents?11 min
  4. Q173How do you stop endless agent loops?11 min
  5. Q190How do you trace and debug an agent run?11 min
  6. Q175What makes a tool-calling loop reliable enough to ship?13 min

Learn it in depth

Last updated on 26 November 2026

Building an AI coding assistant for your team?

I design and build AI agents and the interfaces around them, including the tools, checks and review steps. Book a short call and tell me what your team needs.