Building a Coding Agent From Scratch

The harness, not the model, makes a coding agent good. Build one from scratch — from a bare agent loop to a swarm of cloud agents.

Open-source course $0 to run 8 articles 4 videos Code from scratch Apache-2.0 license

Open-source course by Decoding AI in collaboration with Modal, Opik (by Comet) and Kitaru (by ZenML).

decode in the terminal

$Try the finished agent first — 5 minutes, $0

quickstart.sh
# install uv first if you don't have it:  curl -LsSf https://astral.sh/uv/install.sh | 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 GEMINI_API_KEY — free at https://aistudio.google.com/apikey
$ uv run decode

Then type /demo- and pick a demo — see what they do. Full guide: install_and_usage.md.

The demo skills listed inside the decode TUI after typing /demo-
What opens: type /demo- and the six demos are one keystroke away.

##About This Course

In one public experiment by LangChain, changing only the harness — same model throughout — moved a coding agent from roughly 30th place into the top 5 on Terminal-Bench. The harness decides what the model sees, what it touches, and what happens when it's wrong. It's also the part nobody teaches.

The agent is ~20 lines. The course is everything else.

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)

That's the entire tool-calling agent — the thing people call "the agent" ends here. Everything else in this repo — the permission gate, the sandbox, compaction, the steering queue, the durable runtime, the subagent fan-out, the evals — is the harness. That's what you're here to build.

A fresh decode session: Opik tracing on, a Modal-served Qwen model, skill autocomplete, steering keys in the footer
A fresh session — Opik tracing, a Modal-served Qwen, steering keys in the footer. All harness; none of it in those 20 lines.

We spent months under the hood of Claude Code (via its leaked source), OpenCode, Pi, and Aider, then distilled it into 8 lessons where, from an empty repo, you build decode, your own terminal coding agent. By lesson 2 it asks permission before running bash; by lesson 8 it's deployed to the cloud, building the same feature 5–10× in parallel and handing you back reviewed pull requests. One headless core, two ways to drive it: an interactive TUI wired to a live session, and a remote runtime running N copies in parallel.

Under the hood: a Pydantic AI ReAct loop on Gemini, OpenRouter, or an open model you serve on Modal; file / bash / web / LSP tools and parallel Explore subagents; Docker/Modal sandboxes; a durable Kitaru runtime; Opik tracing and evals.

You walk away with three things:

Skip this layer and you're betting your work on tools you can't inspect.

The code tells you what. The lessons tell you why.

The whole repo is free: clone it, read it, ship it. But anyone can read an agent loop. The lessons cover what code can't — why steering input waits for the next model call instead of injecting mid-tool, why compaction fires at ~80% of the window instead of at the limit, why the sandbox may hold a git token while the model's context never does, why subagent fan-out caps at 6. Every component earns its place, and every lesson walks the reasoning.

decode architecture
Two interface modes on the left, the headless harness on the right, the evals plane underneath.

##See It Work

The finished agent ships with demo skills under .decode/skills/. Open the TUI, type /demo-, pick one, and watch the harness you're about to build do real work:

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 machinery underneath is real infrastructure you'll stand up yourself, not a diagram:

A durable run recorded step by step in Kitaru
Replay and Improve 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 — six live here, ~1.3s cold start
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 — same harness, your model
Sessions traced in Opik with secrets scrubbed
Adding AI Evals & ObservabilityEvery session traced in Opik — note the secrets scrubbed before they reach a log

##You'll Walk Away Knowing How To

Every lesson runs the same way: watch decode do it, then pull out the principle.

decode in plan mode breaking the Snake demo into a task list with the todo tool
Planning for Long-Running TasksPlan mode, live: the agent breaks the Snake demo into a task list with the todo tool — [x] done, [~] in progress.

##Course Outline

Eight written lessons and four videos: video 2 covers lessons 2–3, video 3 covers lessons 4–6. The full codebase is already here; lessons publish progressively on Decoding AI and the links below light up as they go live.

Lesson 1 ● live

Building a Coding Agent From Scratch: Harness Architecture

The map of every component before you write a single line of code.

Lesson 2 ○ next week · video 2

The Agent Loop Plugged Into the TUI (The Interactive Mode)

The ReAct loop, the core tools, and the human approving and steering every turn.

Lesson 3 ○ coming soon · video 2

The Runtime: Durable Execution, HITL & Replays (The Headless Mode)

kill -9 a headless run, resume it from checkpoints, replay it with the model swapped.

Lesson 4 ○ coming soon · video 3

Containing the Agent: Permissions & Sandbox

Four permission modes, then Docker and Modal sandboxes — nothing executes on your machine.

Lesson 5 ○ coming soon · video 3

Context Engineering for Coding Agents

Memory, compaction, skills, and LSP — the context window treated as a budget.

Lesson 6 ○ coming soon · video 3

Agents Catalog, Subagents & Parallel Fan-out

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

Lesson 7 ○ coming soon · video 4

Does It Work? Benchmarks, Regression & Online AI Evals

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

Lesson 8 ○ coming soon

Running Swarms of Remote Agents

Deploy to GCP + Modal and build the same feature 5–10× in parallel — judged, winner merged.

##Who Should Join?

For: engineers who learn by building. You finish with a working coding agent and patterns to steal for your own agentic applications.

Target AudienceWhy Join?
ML/AI EngineersBuild a complete agentic system — loop, tools, sandbox, evals — not another notebook demo.
Software EngineersStop treating the agent in your terminal as a black box.
AI/Platform EngineersThe ops half nobody covers: sandboxing, durability, secrets, observability.

Prerequisites

CategoryRequirements
SkillsPython (Intermediate) · LLMs & agents (Beginner)
HardwareModern laptop/PC. Docker optional (for the local sandbox); everything heavier runs in the cloud.
LevelIntermediate (but with a little sweat and patience, anyone can do it)
Time~4–6 hours for the whole course — 4 if you read and watch, 6 if you run everything.

##Cost Structure

Running the code costs $0 if you stick to free tiers:

ServiceCost
Gemini API (default provider)free tier (Google AI Studio)
OpenRouter (alternative provider)$0 on :free models (optional $10 credit raises the daily cap)
Modal (self-served open models + remote sandbox)$30 free credits
Opik (tracing + evals)free tier
Kitaru (durable runtime)free, runs locally offline
GCP — deploy the agent to run remotely (optional)~$16/month while it's up — see infra.md

Reading-only? Everything's free!

Self-paced and project-based: no paywall, no certificate theater. Read the lesson on Decoding AI, run the matching code, then break it and fix it.

##Sponsors

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, too — star them: Opik on GitHub · Kitaru on GitHub.

##FAQ

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. Claude Code, OpenCode, and Pi picked TypeScript; Go compiles to one tidy binary; and Aider proves Python can carry a serious coding agent. 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.

Why is there no vector database or codebase index?

Deliberately. Memory is plain files — AGENTS.md for your instructions, MEMORY.md for what the agent learns — and the repo is explored just-in-time with grep. Fresh reads beat a stale index, and you get to see exactly what the agent knows.

##Course Author

Paul Iusztin
Paul Iusztin — AI Engineer & Founder of Decoding AI

After shipping 21 AI applications, Paul uses his best-selling LLM Engineer's Handbook, Decoding AI Magazine, and courses like this one to lead 160,000+ AI engineers out of demo purgatory and into production-grade engineering.