← All projects
Complete · 11 build phases

Terminal coding agent

A ReAct-loop agent that reads, writes and runs code from your terminal, inside a sandbox.

Built to understand how coding agents work end to end. The tool system, validator, sandbox and agent loop are hand-built; AI helped only with boilerplate and test scaffolding.

> create a file called hello.py that prints hello world → write_file(hello.py)> run this python code: print(sum(range(101))) → execute_code · validator: safe · docker --network none 5050> search the code for ToolRegistry
StackPython · Claude API · Docker · pytest
Tools7: files, code search, sandboxed execution, git status / diff / commit
SafetyAST validator, then a network-less container with a memory cap
Tested11 tests with the LLM mocked, so they run offline
01

What it does

You type a request in plain English. The agent reasons about it, calls a tool, reads the result and repeats until the task is done: the Reason–Act–Observe loop.

It can create and read files, search a codebase, run Python, check git status and diffs, commit, and rename a symbol across several files by combining search, read and write. When the conversation grows long, older turns are summarized and recent ones kept word for word.

02

Architecture

A request flows through the loop, past the guardrails, to a tool. Every tool returns success with a result, or an error, which the agent reads before its next step.

Architecture: the user request enters the ReAct loop of reason, act and observe; actions pass guardrails for confirmation and snapshots, then reach tools; execute_code goes through an AST validator into a Docker sandbox, with a subprocess fallback
03

Safety: bound what code can do

The design favors limiting what code can do over trying to list everything dangerous it might try.

1 · Static validator, a first filter

Parses the code into an AST and blocks dangerous imports like os, subprocess and socket. Code that won't parse is rejected. It's a blocklist, so it's not the security boundary.

2 · Docker sandbox, the real boundary

Code runs in a container with no network, a hard memory cap, a timeout and its own filesystem. This is the actual containment.

3 · Subprocess fallback

No Docker? Code still runs in a subprocess with a timeout and CPU cap, so the agent works anywhere, as defense in depth.

Guardrails on every write

Destructive actions ask [y/N] and default to no. Files are snapshotted before writes, and /rollback restores them.

The agent kept repeating itself.

Early on, the agent re-ran tools several times for a single request. Tracing the actual message list on each turn showed why: the loop was rebuilding the conversation every iteration instead of adding to it, so the model never saw its own earlier tool calls.

The fix was one growing message list. A second surprise came from testing on two platforms: Linux honors the memory limit and macOS rejects it, and the CPU cap kills with a different signal on each. Limits the OS refuses are now skipped instead of crashing.

Beforetools re-run per request
Afterone growing message list
Found bytracing each turn, not guessing
05

Key engineering decisions

Default-deny confirmation

A destructive action runs only on an explicit yes. Pressing Enter, or anything else, means no.

Git as three single-purpose tools

Status, diff and commit are separate tools rather than one general git command, so the agent can't compose something destructive. Structure prevents the mistake instead of a check catching it.

Tests mock the LLM

The suite runs offline with no API key and asserts real behavior: the loop stops, tools are dispatched, errors surface. Not just that code ran.

Hand-build the load-bearing parts

The tool registry, validator, executor and loop were written by hand to understand them; boilerplate and test scaffolding were AI-assisted and then reviewed.

06 · Known limitations
  • Multi-file refactoring is verified only on small cases, since it rewrites whole files
  • Without Docker, the validator can be evaded, so the fallback is defense in depth, not a boundary
  • No hard filesystem boundary: tools stay in the working directory by convention
  • The LLM provider is built in the constructor, coupling it to a live API key
07 · Next
  • A line-level edit tool, so refactoring scales to large files
  • Container hardening: seccomp, a read-only root filesystem, dropped capabilities
  • Enforced path sandboxing for every file tool
  • Dependency injection for the LLM provider