
Agent Harnesses: The Loop Around the Model Matters More Than the Model
An architect's view on building robust AI agent systems
As a software architect, I've found that the agent harness, the operational layer wrapped around a large language model (LLM), is often more critical to an AI agent's performance and capabilities than the LLM itself. It's the harness that transforms a text-in, text-out model into an intelligent agent, dictating its actions, memory, and interactions with the outside world.
TL;DR
The agent harness is the orchestrator that augments an LLM with memory, tools, context management, and permissions, essentially defining the agent's behavior. Different harnesses, like Pi, OpenCode, Hermes, or OpenClaw, lead to vastly different agent capabilities because they implement these augmentations differently. For production and multi-user environments, running the harness outside the sandbox is crucial for security, resource efficiency, and managing state, despite requiring custom solutions for durable execution and filesystem abstraction.
What Exactly Is an Agent Harness?
An LLM on its own is a powerful text generator, but it's stateless. It doesn't remember past interactions, nor can it directly interact with external systems. This is where the agent harness comes in. It's everything around the model that converts its raw token outputs into meaningful actions.
Think of the harness as an intelligent control loop. It crafts the prompts sent to the LLM, processes the LLM's responses, executes any tool calls the model requests, stores session data, and enforces guardrails. This loop, often based on the Reason and Act (ReAct) pattern, instructs the model to iteratively reason, act, and observe until a task is complete. Even "old" techniques like ReAct, dating back to 2022, are still fundamental to how many frameworks operate.
For example, an educational framework like TinyAgent, comprising about 600 lines of Python code, demonstrates this core loop. It connects a local model like Gemma 4 to modules for memory and tools. Production-grade harnesses, however, are significantly larger, handling complex memory systems, state across multiple sessions, and extensive guardrails.
Why the Same LLM Behaves Differently in Different Harnesses
If you take the exact same LLM and place it within different harnesses, you'll observe four completely distinct agents. This isn't magic; it's a direct consequence of how each harness is designed and what capabilities it provides. The model weights are identical, but the harness provides the scaffolding that makes the agent functional.
Consider the varying philosophies of popular harnesses:
- Minimalism vs. Complexity: Pi might be minimalistic, offering basic augmentation, while OpenClaw, with over 30 chat channels, is quite hefty. Hermes, for instance, loops skills back into its memory, adding a layer of persistence and learning that a simpler harness might lack. OpenCode uses a shared server for different clients, indicating a multi-user design from the start.
- Tooling: The number and types of tools a harness exposes to the LLM dramatically influence what an agent can do. A harness might offer simple file read/write operations, or it could integrate with complex APIs, CI/CD pipelines, or external databases. The specific protocol for tool use, like the
read:orwrite:commands in some coding agents, defines how the model signals its intentions and how the harness executes them. - Context Management: While the LLM has a context window, the harness manages what goes into that window. It decides which memories are relevant, which parts of a code repository to show, and how to structure the prompt to guide the model. A master programmer keeps the context window clean, ensuring the agent remembers what matters and avoids token waste from irrelevant information.
- Guardrails and Permissions: The harness is responsible for setting boundaries. It can enforce allowlists for commands, manage access to sensitive data, and prevent the agent from performing unauthorized actions. Without a robust permission model, an agent might, for example, expose a deploy key if prompted by an untrusted input. This is why you should never give one agent all three: private data, untrusted input, and a way to send data out.
Ultimately, the harness is where the programmer's work happens. It defines the runtime, the specs, the task lists, checks, and records the agent uses, which are far more influential than the underlying model's raw generative power.
Why the Harness Belongs Outside the Sandbox
This is a critical architectural decision, especially for multi-user or production environments. Running the agent harness outside the sandbox, rather than inside the same container as the code it's working on, offers significant advantages in security, resource management, and scalability.
Harness Inside the Sandbox (e.g., local Claude Code SDK):
- Pros: Simple execution model (one container, one process tree, local filesystem), easy reuse of off-the-shelf harnesses. Skills and memories can be simple files on the local filesystem.
- Cons: Credentials (like LLM API keys) are exposed within the sandbox, increasing security risk. You can't easily suspend the sandbox when idle, leading to wasted resources. Losing the sandbox means losing the session. Multi-user scenarios become a distributed filesystem problem, as shared state is difficult to manage across ephemeral containers.
Harness Outside the Sandbox (Mendral's approach):
-
Pros:
- Security: Credentials (LLM API keys, user tokens, database access) remain with the harness on your backend, outside the sandbox. The sandbox only contains the environment needed for the agent's work, with nothing for it to escape to. This simplifies permission models significantly.
- Resource Efficiency: Sandboxes can be provisioned only when a command needs to run and suspended when idle. This is crucial as an agent often spends significant time thinking, calling external APIs, or waiting for processes like CI, which don't require an active sandbox. Tools like Blaxel can resume a sandbox from standby in as little as 25ms, making this transition nearly imperceptible.
- Durability and Scalability: Agent sessions can run for hours and must survive deploys or instance failures. By having the harness manage the loop, durable execution becomes possible. For example, using a system like Inngest, each turn of the agent loop can be checkpointed. If the server restarts, the loop picks up where it left off. This makes sandboxes "cattle," meaning they can be treated as ephemeral and easily replaced if one dies mid-session.
- Multi-User State: Shared skills and memories across multiple engineers become a shared database problem, which is well-understood, rather than a distributed filesystem challenge.
-
Cons: Off-the-shelf local harnesses don't work directly, as they assume a local filesystem. You need to abstract the filesystem, meaning skills (e.g.,
.claude/skills/foo.md) and memories (e.g.,.claude/memory/MEMORY.md) can't just be files in a disposable sandbox. This requires custom solutions for state persistence.
Choosing or Building an Agent Harness
When deciding whether to adopt an existing harness or build your own, consider your specific needs and constraints. For a simple, single-user developer tool, a local, "harness inside sandbox" approach might suffice, perhaps using a tool like Claude Code SDK. However, for anything beyond that, especially multi-user or production systems, the benefits of building a harness outside the sandbox become clear.
If you're building, you'll need to address:
- Agent Loop: This is the core. It maintains conversation history and drives turn-by-turn interaction. It's what differentiates a tool like TinyAgent, which has about 600 lines of code, from a simple chat interface.
- Tool Use Protocol: Define how the model signals actions and how the harness interprets and executes them. This can be as simple as parsing specific command formats like
read:relative/pathor integrating with complex APIs. - Sandboxing: Implement a secure way to restrict file access to a nominated working directory, preventing the agent from operating outside its intended scope. This is a basic form of security.
- State Management: For an outside-the-sandbox approach, you'll need a robust solution for skills, memories, and other agent state that would typically reside on a local filesystem. This means using a database or other persistent storage, rather than relying on ephemeral sandbox files.
- Durable Execution: Implement a mechanism to ensure long-running agent sessions can survive infrastructure changes or failures. Solutions like Inngest are designed for this.
- Context Engineering: The harness must intelligently manage the context window, feeding the LLM only the most relevant information for the current task. This prevents token waste and improves agent performance. You can read more about this in my post on Context Engineering for AI Agents Matters More Than Clever Prompts.
For teams aiming to integrate AI agents deeply into their engineering workflows, particularly for tasks like automated pull requests or complex system interactions, a well-architected harness is non-negotiable. If you're exploring how to build or integrate AI agents into your systems, considering a fractional tech lead or specialized AI agent development services can provide the architectural guidance needed to navigate these complexities.
Practical Takeaways
- The harness is the agent's brain and body. The LLM is the reasoning core, but the harness provides the memory, senses (tools), and motor functions (action execution).
- Harness choice dictates capability. Even with the same LLM, different harnesses (Pi, OpenCode, Hermes, OpenClaw) create agents with wildly different behaviors due to varying toolsets, memory systems, and guardrails.
- Security by design. For multi-user or production systems, run the harness outside the sandbox to protect credentials and manage resources efficiently.
- Abstraction is key. When running outside the sandbox, abstract away the local filesystem for agent state (skills, memories) and ensure durable execution for long-running sessions.
What I Would Do
For any serious, multi-user AI agent deployment, I would always advocate for building or adopting a harness that runs outside the sandbox. The security implications of exposing credentials within an ephemeral sandbox are too great, and the resource inefficiencies of constantly running sandboxes are unsustainable. I'd prioritize durable execution from day one, leveraging tools like Inngest for checkpointing agent loops.
I would also invest heavily in designing a robust tool-use protocol and a flexible context management system. The ability to give the LLM precise, limited tools and to control exactly what information it sees is paramount for both security and effectiveness. This means moving beyond simple file-based memory and towards a more structured, database-backed approach for agent state, even if it requires more initial development effort. This approach ensures that the agent, while powerful, remains within the defined operational boundaries and aligns with enterprise-level security and operational requirements.
Sources
- https://newsletter.maartengrootendorst.com/p/a-visual-guide-to-agent-harnesses
- https://www.mendral.com/blog/agent-harness-belongs-outside-sandbox
- https://www.vivekchopra.com/posts/tao-of-coding-with-agent-harnesses
- https://www.appsoftware.com/blog/building-a-bad-local-ai-coding-agent-harness-from-scratch
Subscribe to my newsletter
Read articles from Tech With Asim | Learn, Build, Lead directly inside your inbox. Subscribe to the newsletter, and don't miss out.
More Articles

AI Pair Programming: Treat AI as a Partner, Not an Autopilot
Autopilot mode ships what you do not understand. Pair mode ships what you can explain. How to get the most from AI by treating it as a smart but sometimes wrong colleague.

Advent of Code Without AI: A December Challenge for Developers
Advent of Code brings a small programming puzzle every day in December. My challenge: solve a few without AI, then compare your solution with an AI's and learn from both.

When Not to Use AI: Sometimes You Should Just Read the Code
Sometimes the fastest way to fix a bug is still reading the code. How to notice the prompt loop, step away from AI, and come back with a much better question.




Comments