How Open-Source Agent Infrastructure Is Built: Architecture, Tool Governance, and Sandboxing
This article explains why agent quality depends on the runtime system around the model, not the model alone. It clarifies four commonly confused concepts, walks through a plugin-based architecture, the execution loop and tool governance, sandbox and permission hardening, context engineering for long tasks, and practical deployment advice with cloud services.
1. Why the Focus Is Shifting from Models to Runtime Systems
Public discussion of AI coding tools has mostly centered on the model: better code comprehension, longer context windows, more stable complex reasoning, and lower inference cost. These metrics matter. But once you place a model inside a large repository containing hundreds of thousands of files and ask it to work continuously for tens of minutes or even hours, the final delivery quality is rarely determined by the model alone.
The reason is that a model’s capability boundary does not overlap with a task’s execution boundary. The model needs to know what is in the current working directory, which files were just modified, which command failed, and what the real error in the test output is. It also has to retain key facts as the context keeps growing, so it does not “forget” the original constraints. Meanwhile, real engineering environments are full of irreversible operations: deleting branches, force-pushing, overwriting uncommitted changes, running destructive scripts. The cost of a single misjudgment can be far higher than that of a reasoning error.
The system that surrounds the model is therefore commonly called the Agent Harness. Its responsibility can be summarized in one sentence: the model decides what to do next, and the runtime system makes those decisions land safely, reliably, and traceably.
2. Four Concept Boundaries That Are Easy to Confuse
Before discussing infrastructure, it helps to separate a few concepts. Otherwise, architecture choices go off course from the start.
A model is not an agent. A model receives messages and generates the next piece of text or a tool-call intent. It does not inherently know the file system layout, nor does it naturally have terminal, editor, version control, browser, or database access. A model outputting the intent to “read a file” is a completely different thing from the file being reliably read and fed back into the context.
A tool protocol is not an agent. The Model Context Protocol commonly used in the industry addresses how tools, resources, and prompts are exposed in a standard way. It defines the interface layer, not the execution layer. It does not automatically provide a complete task loop, session recovery, context compression, permission decisions, or execution state management.
An application framework is not the same as a runtime framework. Many orchestration frameworks are oriented toward helping developers build business flows and node connections, and what they produce is a skeleton whose runtime details you must fill in yourself. A runtime framework is more like a complete execution environment that can host an agent out of the box: it actually issues model requests, schedules tools, spawns subprocesses, persists logs, handles user approvals, and provides an interactive interface.
A demo script is not infrastructure. A script that completes one fix in a single repository is very different from infrastructure that can be reused by many people, across many repositories, over long periods. The difference lies in observability, recoverability, and the permission model.
3. Plugin Architecture: Turning the Agent into a Recombinable Tree
A shared trend among the new generation of open-source runtime frameworks is to make “everything is a plugin” a core design principle. Model adapters, the main loop, the tool registry, session logs, the sandbox, approval policies, context compression, sub-agents, and even the graphical interface all exist as plugins, driven underneath by a dependency injection and lifecycle management container.
The direct result is that the agent is no longer a closed monolith but a plugin tree that can be recombined at startup and replaced or unloaded at runtime.
A schematic configuration structure usually looks close to the following (structure only, not a specific implementation):
plugins:- model-adapter: { provider: local, max_output_tokens: 8192 }- tool-registry: { allow: [fs.read, fs.write, shell.exec, git.status] }- sandbox: { mode: workspace, network: deny }- approval: { policy: ask_on_write, timeout: 120s }- context: { compress_at: 0.7, keep: [constraints, todo] }- session-log: { sink: object_storage, rotate: 100MB }- subagent: { max_depth: 2, max_parallel: 4 }- web-ui: { bind: 127.0.0.1 }
The engineering value of this design shows up in four areas.
The first is replaceability. Switching model providers only requires replacing the adapter plugin; the main loop and tool layer need no changes, which leaves room for multi-model canary rollouts and cost optimization. The second is trimmability. Scenarios that do not need a graphical interface can simply skip loading the UI plugin, reducing the attack surface and resource usage. The third is composability. Approval policies, sandbox modes, and log destinations can be combined as needed to form different risk tiers. The fourth is evolvability. Adding a new tool or a new context compression strategy can be done through a plugin, without touching the core loop.
It is important to recognize that plugin architectures also amplify supply chain risk. Plugin sources, versions, and permission declarations must be governed; otherwise, “pluggable” turns into “injectable.”
4. The Execution Loop and Tool Governance: The Real Source of Stability
The main loop usually follows a closed cycle of “request, parse, execute, feed back, request again.” It looks simple, but the engineering difficulty concentrates in the exception paths:
- Tool call failures must be localized. A non-zero exit, a timeout, or overly long output from a single command should be fed back to the model as a structured result, rather than throwing an exception that terminates the whole session.
- Dangerous operations must be intercepted up front. Force pushes, recursive deletes, changes to global configuration, and access to paths outside the working directory should be blocked by rules or a policy plugin before execution.
- Long tasks must be recoverable. Session logs need to persist key state so that after a process interruption the agent can continue from the most recent consistent point instead of rerunning from zero.
- Sub-agents must be controlled. Parallel task decomposition can improve throughput, but recursion depth, concurrency, and total budget must be limited to avoid resource divergence.
The quality of tool descriptions directly determines call accuracy. Names, purposes, parameter constraints, return structures, and failure semantics should all be as clear as possible, and tool results should stay concise and parseable, avoiding flooding the context with large blocks of irrelevant output.
5. Sandboxing and Permissions: The Most Underrated Part in the Preview Stage
It must be stated clearly: a dynamically loaded plugin sandbox is usually only an isolation boundary, not a strong security boundary. It is not equivalent in threat model to OS-level strong isolation such as virtualization-based containers or micro virtual machines. The presence of a sandbox alone does not mean production repository permissions can be opened up.
Before connecting important repositories during the preview stage, at least the following hardening is recommended:
- Pin versions. Lock the runtime framework and all plugin versions, disable automatic upgrades, and route changes through review.
- Narrow plugin sources. Allow only plugins from trusted sources, verify integrity, and prohibit pulling unknown code at runtime.
- Choose an appropriate sandbox mode. Select among “working directory only,” “restricted container,” and “strong isolation” based on task risk, using strong isolation for high-risk tasks.
- Isolate credentials. Inject short-lived credentials or use a proxy so long-term keys never enter an environment the agent can read, and prohibit credentials from appearing in logs.
- Minimize network access. Deny outbound access by default and allow only the necessary package sources and API endpoints as needed.
- Whitelist persistent directories. Allow writes only to designated workspaces and temporary directories; keep all other paths read-only.
- Full auditing. Record every tool call, parameter summary, approval result, and actor identity, with logs shipped to a dedicated logging service or object storage.
6. Context Engineering: Keeping Long Tasks from “Amnesia”
Context compression is not simple truncation. More mature approaches include preserving the original constraints and acceptance criteria, maintaining a structured task list, summarizing and archiving completed historical tool outputs, and re-injecting key facts after compression. The compression trigger threshold, retained fields, and summary granularity should all be configurable, and session logs should be used to review whether compression dropped necessary information.
7. Deployment Advice and Cloud Support
For teams that want to build their own runtime environment, start by validating the loop on a low-risk repository, then expand the scope gradually. On the cloud, general-purpose capabilities are usually enough: container platforms for isolated execution, object storage for session logs and artifacts, logging services and monitoring alerts for observability, message queues for long-task scheduling, and a key management service for short-lived credentials. Baidu AI Cloud offers corresponding capabilities in these general categories and can serve as the foundation for a self-built runtime framework.
Overall, the maturity of agent infrastructure does not depend on supporting more flashy plugins. It depends on whether failures are recoverable, whether privilege violations are blocked, and whether actions are traceable after the fact. Get these three things solid, and improvements in model capability can truly translate into stability in engineering delivery.
