decode
decode logo decode Free open-source course

Building a Coding Agent From Scratch

The harness, not the model, makes a coding agent good.

Build one from scratch, from a bare-bones agent loop to a swarm of cloud agents.

By Decoding AI, in collaboration with Modal, Opik (by Comet), and Kitaru (by ZenML).

decode — the finished agent
decode in the terminal
Open-source course $0 to run 8 articles 4 videos Code from scratch Apache-2.0 license
Quickstart01

Try The Finished Agent First.

5 minutes / $0
quickstart.sh
$ git clone https://github.com/decodingai-magazine/building-a-coding-agent-from-scratch-course.git
$ cd building-a-coding-agent-from-scratch-course
$ make install
$ cp .env.example .env # set LLM API key
$ uv run decode

Then type /demo- and pick a demo — see what they do below. Full setup guide.

decode — /demo-
The demo skills listed inside the decode TUI after typing /demo-
Type /demo- and the six demos are one keystroke away.
About this course02

The Agent Is ~20 Lines. The Course Is Everything Else.

In LangChain's Terminal-Bench test, changing only the harness moved an agent from ~30th to top 5. The harness, not the model, wins.

That's the entire tool-calling agent. Everything else in this repo is the harness: tools, skills, permissions, sandbox, steering, memory, compaction, durable runtime, subagents, evals.

That's what you're here to build.

the entire agent
agent = Agent(
build_model(settings.llm_provider), # gemini | openrouter | modal
deps_type=AgentDeps, # cwd, event sink, permission gate
output_type=[str, DeferredToolRequests], # final answer, or tools paused for approval
)
register_tools(agent) # read, edit, bash, grep, ...
 
async with agent.iter(prompt, message_history=history) as run:
async for node in run: # model request → tool calls → repeat
stream_events(node)

We spent months inside Claude Code (via its leaked source), OpenCode, Pi, and Aider, then distilled it into 8 articles and 4 videos where you'll build decode, your own coding agent, from scratch: one headless core, two modes, N agents in parallel.

a fresh session
A fresh decode session: Opik tracing on, a Modal-served Qwen model, skill autocomplete, steering keys in the footer
A fresh session powered by Qwen 3.6 35B hosted on Modal
the architecture
decode architecture
Two interface modes on the left, the headless harness on the right, the evals plane underneath.
Course outline03

Eight Lessons. Four Videos.

From designing the harness to deploying a swarm of remote agents.

5 live 3 coming
Lesson 1 — the harness architecture
Lesson 1 live video 1 coming soon

Harness Architecture

Designing the harness around the model, from the agent loop to a remote swarm.

Lesson 3 — from a raw shell to a sandboxed coding agent
Lesson 3 live video 2 coming soon

From a Raw Shell to a Sandboxed Coding Agent

Safely execute your agent's commands locally via Docker or remotely via Modal.

Lesson 5 — subagents are context engineering
Lesson 5 live video 2 coming soon

Subagents Are Context Engineering

One call fans out N parallel subagents, each with a budget and a report contract.

Lesson 6 soon video 3

Remote Headless Mode & Durability

kill -9 a headless run, resume it from checkpoints, then deploy to GCP + Modal and run the same feature 5–10× in parallel.

Lesson 7 soon video 3

AI Evals Foundations: Benchmarks, Regression and Online

Benchmarks, regression probes, and online evals: does it work, still work, keep working?

evals.md
Lesson 8 soon video 4

AI Evals on Steroids via Replays

Replay a recorded run with the model or a checkpoint swapped, then diff the two executions.

Why the lessons04

The Code Tells You What. The Lessons Tell You Why.

The articles and videos cover what the code can't. The why behind every decision.

01

Why a headless harness with two interface modes, TUI and Remote.

02

What the essential components of a coding agent are, and what is optional.

03

Why we plugged in 9 tools, no more, no less.

04

Why we need a durable runtime and replays.

05

What guardrails are actually useful.

06

Why compaction fires at ~80% of the window instead of at the limit.

07

Why you need benchmarks, regression tests and online evals.

See it work05

Six Demos. One Keystroke Away.

Demo skills live under .decode/skills/. Type /demo- in the TUI, pick one, and watch the harness do real work.

The demo skills listed inside the decode TUI after typing /demo-
Implement the Skills StandardType /demo- and the six demos are one keystroke away.
A playable Snake game built by decode
Capable of Creating Games/demo-1-terminal-arcade — one prompt, a playable Snake game
Live GitHub repo data rendered as a web dashboard
Fetching Data & Creating Dashboards/demo-3-repo-pulse — live GitHub API data rendered as a dashboard
An interactive knowledge graph scraped from web articles
Extracting Ontologies & Rendering Graphs/demo-6-article-kg — web articles scraped into an interactive knowledge graph

And the infra that powers the agents.

A durable run recorded step by step in Kitaru
Durability & Replay for AI AgentsEvery run recorded step by step in Kitaru — kill it, resume it, replay it with the model swapped
Live Modal sandboxes executing the agent's tools
Remote SandboxingThe agent's bash runs in disposable Modal sandboxes
A self-served open model endpoint on Modal
Powered by Open Source ModelsYour own Qwen3.6-35B served on an H200 via a Modal endpoint
Sessions traced in Opik with secrets scrubbed
Adding AI Evals & ObservabilityEvery session traced in Opik
Outcomes06

You'll Walk Away Knowing How To

Design a coding agent harness from scratch
Implement a headless coding agent loop
Attach the headless harness to multiple modes: TUI and remote
Add a runtime for durable execution, human-in-the-loop and replays
Implement guardrails: a permission layer plus local & remote sandboxing
Build essential context engineering techniques: memory, compaction, skills
Hook up an LSP server for faster feedback loops
Implement an agents catalog: build, plan, code reviewer and exploration agents
Spawn parallel subagents via fan-out strategies
Add observability
Design an eval harness for benchmarking and catching regressions
Deploy and run swarms of agents
decode in plan mode breaking the Snake demo into a task list with the todo tool
Plan mode, live: the agent breaks the Snake demo into a task list with the todo tool — [x] done, [~] in progress.

Tech Stack

The code is written in Python, with the following frameworks and libraries:

Agent framework
LLM providers
Modal (open weights you serve yourself via SGLang), OpenRouter (open weights as a service), or Gemini (proprietary)
Durable runtime & replays
Observability & evals
Sandboxing
Local Docker & remote Modal sandboxes
Deploying
GCP & Modal

Otherwise, we build everything from scratch, to teach foundations that last, not frameworks that hide the hard parts.

Who should join07

Engineers Who Learn by Building.

You finish with a working coding agent that teaches you harness engineering patterns to steal for your own agentic applications.

Best for
ML/AI Engineers levelling up their craft
Software Engineers and Data Scientists moving into agentic systems
Skills
Python (Intermediate), LLMs & agents (Beginner)
Hardware
Any modern machine will do. No GPU required, as we run all the LLMs in the cloud.
Level
Intermediate (but with a little sweat and patience, anyone can do it)
Time
~4–8 hours for the whole course — 4 if you read and watch, 6–8 if you run everything.
Cost structure08

Running It Costs $0.

If you stick to free tiers. Reading only? Everything's free, full stop.

ServiceCost
Gemini API (default provider — easy setup, but limited API requests)free tier (Google AI Studio)
Modal (recommended provider + remote sandbox)$30 free credits — enough to run the course
OpenRouter (alternative provider)$0 on :free models (optional $10 credit raises the daily cap)
Opik (tracing + evals)free tier
Kitaru (durable runtime)free, runs locally offline
GCP — deploy the agent to run remotely (optional)~$16/month while up; new accounts get $300 in credits. infra.md
Project structure09

One Module Per Concept.

One Python package; each module maps to one part of the architecture.

How it works

Self-paced, based on this repository plus the lessons that walk you through the code. No paywall. No platform.

Read the lessons on the Decoding AI Magazine, watch the videos on the Decoding AI Channel, run the code on your own machine, break it, fix it, and learn from the process.

tree -L 2
.
├── docs/
│   ├── adr/                  # Architecture Decision Records — the "why" of every choice
│   ├── glossary.md           # one canonical name per concept
│   └── evals.md              # the four-track eval suite, mapped
├── evals/                    # benchmark + regression probes + demo skills
├── tests/{unit,integration}/ # mirrors src/ 1:1; milestone capstones prove each milestone
└── src/decode/
    ├── cli.py                # Click entrypoint → launches the TUI
    ├── tui/                  # input: prompt_toolkit · output: Rich
    ├── harness/              # message queue + priority gate around the loop
    ├── agent/                # the Pydantic-AI ReAct loop (LLM ⇄ tools)
    ├── agents/               # agents catalog: Build / Plan / Code-Reviewer + Explore subagent
    ├── tools/                # file I/O, bash, web, todo, skills dispatch, LSP, ask_user
    ├── permissions/          # allow/ask/deny · modes · settings.json
    ├── sandbox/              # bash + file tools seam: none (host) / docker / modal
    ├── services/lsp/         # hand-rolled stdio LSP client (ty)
    ├── runtime/              # Kitaru durable flow: decode run / replay / HITL
    ├── context/              # compaction + conversation log (JSONL)
    ├── memory/               # AGENTS.md / MEMORY.md loading + write-back
    ├── observability/        # Opik tracing
    └── config/, entities/    # settings singleton · shared models
Running the code10

One Guide Per Side Quest.

Everything lives under running_the_code/. One core guide, plus one focused guide per side quest.

install_and_usage.mdStart here troubleshooting.mdEvery known failure, and its fix modal_models.mdServing open models on Modal runtime.mdRuntime setup for headless mode sandboxing.mdDocker (local) / Modal (remote) setup for sandboxing credentials.mdEnvironments & secrets, walked end-to-end infra.mdDeploying the remote runtime to GCP and Modal

Questions or setup trouble: open a GitHub issue. Found a bug and know the fix? Fork, fix, run make ci (no API key needed), and open a pull request.

This Course Is Free Thanks to Them.

Sponsored by Modal, Opik and Kitaru

Special thanks to Modal, Opik (by Comet), and Kitaru (by ZenML) for sponsoring this open-source course and keeping it free.

Opik and Kitaru are open source. Consider starring their repositories: Opik on GitHub · Kitaru on GitHub.

FAQ11

Asked and Answered.

Do I need a paid API key?

No. The default Gemini provider has a free tier, OpenRouter routes across :free models, and Modal gives $30 in credits — see Cost Structure.

Why Python and not TypeScript or Go?

Accessibility: our audience knows Python. The course focuses on the design decisions, which transfer to any language.

Why build from scratch instead of extending Pi, DeepAgents, or an existing harness?

Because adding custom logic to an existing harness is the easy part. Knowing what to add requires understanding the internals. That's the fundamentals, and it's what still makes AI engineers valuable. Build a coding agent once, and you're equipped to build a custom agent for any use case.

Course author
Paul Iusztin
Paul Iusztin
Senior AI Engineer, Educator & Founder of Decoding AI
Author of the best-selling LLM Engineer's Handbook.
Decoding AI
Decoding AI Magazine
Join 40k+ engineers learning to build coding agents from scratch with the Decoding AI Magazine.

One More Thing.

If you found this course useful, consider starring the repository so others can find it too.

Star the repo Start Lesson 1