How Coding Agents Work: Harness Engineering and Practical Architecture
This article explains how a coding agent is built and why the engineering layer around the model often matters more than the model itself. Using a source code leak as a starting point, it introduces harness engineering and breaks down a practical five-layer architecture: context, tools, orchestration, and governance. It covers layered context retrieval, structured tool design, the stateful agent loop with termination conditions, and sandbox and audit controls. It also explains why this architecture works, along with rollout advice and common pitfalls for teams building similar systems.
How Coding Agents Work: Harness Engineering and Practical Architecture
From a Source Code Leak
A while back, a leading coding tool accidentally uploaded debug symbol files during packaging because of a configuration oversight in its release pipeline. This exposed hundreds of thousands of lines of client-side code. Once the initial buzz faded, the industry’s attention shifted to a technical question: what is actually inside a coding agent’s client?
One boundary is worth clarifying first: what leaked was the client-side scheduling and orchestration code, not the underlying model weights or training code. That distinction matters, because it points to a collective shift in how the industry thinks about these systems. What usually determines whether a coding agent is useful is not the model itself, but the engineering system wrapped around it.
Harness Engineering Is Not a New Idea
The industry has started using a term more and more: harness engineering. It sounds elaborate, but stripped of the packaging, it describes something simple. Instead of waiting for the model to get smarter and stop hallucinating, you constrain it with a system, put it on a leash, and keep it inside defined lanes.
This shift comes from engineering reality. A large model’s output is fundamentally probabilistic sampling and therefore uncertain, while software engineering demands determinism, repeatability, and the ability to roll back. That gap cannot be closed by waiting for the next model generation; it has to be filled by an external system. Harness engineering is the umbrella term for that system, and it carries at least four responsibilities:
- Context supply: deciding what information the model sees at each step.
- Action space constraints: deciding what the model can and cannot do.
- Feedback loops: deciding how the model learns whether its output is right or wrong.
- Safety boundaries: deciding how bad the worst case can get.
Breaking Down the Core Architecture
A usable coding agent typically has five layers, from bottom to top: the model layer, the context layer, the tool layer, the orchestration layer, and the governance layer.
Context Layer: The Real Bottleneck
In practice, context management causes far more problems than model selection. The things you have to handle include the repository’s directory structure, semantic summaries of relevant files, type and dependency graphs, conversation history, and the execution results returned by tools.
A common mistake is stuffing the entire repository into the context. It is expensive, inefficient, and triggers a “lost in the middle” effect, where key information gets buried in noise. A better approach is layered retrieval:
Layer 1: Repository skeleton (directory tree + one-line summary of each module's responsibility)Layer 2: Symbol index (class/function signatures + reference relationships)Layer 3: File contents and snippets pulled on demandLayer 4: Runtime information (test results, logs, error stacks)
Pure vector similarity is not reliable enough for retrieval, because code tasks often depend on exact identifier matching. The industry commonly uses a hybrid of keyword search and semantic search, then adds a second round of expansion based on the reference graph.
Tool Layer: Turning Capabilities into Callable Actions
An agent’s ceiling is set by its toolset. A pragmatic toolset usually includes file read and write, exact string replacement, directory listing, search queries, command execution, and test running.
A few rules of thumb apply to tool design. First, tool granularity should match the task semantics: “replace a specific symbol” is less error-prone than “edit a file.” Second, return values must be structured and length-bounded, so a single command cannot flood the context with tens of thousands of lines of logs. Third, every tool should declare its side-effect level, treating read-only operations, reversible writes, and irreversible operations differently.
Orchestration Layer: Loops, State, and Termination
A coding agent’s runtime is essentially a stateful loop:
while not done and step < MAX_STEPS:ctx = context.build(state) # Assemble contextaction = model.plan(ctx, tools) # Model decidesresult = executor.run(action) # Execute in sandboxstate = state.update(action, result) # Update state and memorydone = verifier.check(state) # Verify whether the goal is met
Three details separate good implementations from bad ones: whether the termination condition is explicit, whether failed retries have a cap, and whether rollback checkpoints are preserved. Without these, an agent easily falls into a loop of repeatedly editing the same piece of code.
Governance Layer: Permissions, Sandboxing, and Auditing
The governance layer determines whether the system can go to production. The core measures include running the execution environment inside containers or isolated sandboxes; using path allowlists for filesystem write permissions; intercepting dangerous patterns in command execution; introducing human confirmation for high-risk actions; and logging the full chain of operations for auditing and replay.
Why This Architecture Works
Back to the original framing: the model is a wild horse, and the harness is the reins. The architecture works because of three mechanisms.
The first is shrinking the search space. With precise retrieval and structured tools, the model does not have to guess blindly among infinite possibilities; it chooses from a limited set of actions, and the error rate drops significantly.
The second is building external feedback. Results from tests, type checks, and static analysis are fed back to the model, forming a closed loop. This is far more reliable than asking the model to “reflect on itself,” because the feedback signal comes from objective execution rather than the model’s self-assessment.
The third is limiting the blast radius. Sandboxes and permission boundaries ensure the worst case is a polluted, rollback-able environment, not damaged production data.
Rollout Advice and Common Pitfalls
For teams about to build a similar system, the recommended order is: start with read-only Q&A to validate retrieval quality; then add writes and command execution with a sandbox in place; then connect automated verification to close the loop; and finally add auditing and cost monitoring.
Four pitfalls deserve attention: unbounded context growth that drives costs out of control; untruncated tool return values that cause parsing failures; missing step and retry caps that create infinite loops; and overly broad permissions that keep a demo system from entering a real development workflow.
On the cloud, you can use a container platform to host the sandbox execution environment, object storage to keep repository snapshots and checkpoints, a message queue to decouple long-running tasks, and logging plus monitoring and alerting to observe the call chain and costs. These are generic capability categories and do not point to any specific vendor.
Conclusion
The most valuable thing about the source code leak is not the implementation details it revealed, but that it confirmed an emerging industry consensus: a coding agent’s competitiveness has moved from “how strong the model is” to “how stable the harness is.” Get context, tools, orchestration, and governance right, and even a general-purpose model can deliver a stable, usable engineering result.
