AI Coding Agent Architecture: Containment-First vs. Analyze-First
This article explores two primary architectural philosophies in AI coding agents: Containment-First and Analyze-First. It examines how their fundamentally different approaches to security—relying on kernel-level isolation versus LLM classifiers—cascade into distinct design choices across security models, tool systems, context costs, multi-agent strategies, and user experiences. A decision framework and layered defense strategy for production environments are also provided.
1. Introduction: A Philosophical Divergence, Not a Capability Gap
In the engineering practice of AI coding agents, two implementation paths present nearly mirrored design orientations: one pursues high flexibility with strong boundaries, while the other pursues low flexibility with strong presets. On the surface, this seems like a difference in feature checklists, but essentially, it is a divergence of engineering philosophies: Containment-First versus Analyze-First.
Understanding this is crucial: most differences between these two systems are not seven or eight independent product decisions, but the cascading projections of a single fundamental choice across different layers. Grasping this root issue allows you to deduce the inevitability of the remaining designs.
2. Core Cognitive Framework: Two Answers to One Question
All differences can be boiled down to one question: How do we ensure the safety of the agent when executing commands?
- Route A (Containment-First): Do not trust the model’s judgment; use OS kernel capabilities to limit what the agent “can do.” The security boundary is provided by deterministic mechanisms.
- Route B (Analyze-First): Do not fully trust the model, but do not rely on the kernel either. Instead, introduce an LLM classifier and a multi-layer permission system to review what the agent “wants to do.” The security boundary is provided by the correctness of the analysis.
Once this choice is made, tool count, cross-platform cost, failure UX, observability, and token overhead will all be pushed to their respective extremes based on their own logic.
3. Dimension 1: Security Models
3.1 Mechanism Comparison
| Comparison Item | Route A: Kernel-Level Sandbox | Route B: Classifier + Permission Layer |
|---|---|---|
| Core Mechanism | Kernel mandatory access control, syscall filtering, user-space namespace isolation | Model classifier scoring + path whitelist/blacklist + interactive approval |
| Interception Point | Kernel, deterministic interception | Semantic judgment before execution |
| Bypass Resistance | Very high | Relatively low, relies on analysis correctness |
| Unknown Attacks | Directly blocked via capability trimming | May be bypassed (unseen by classifier) |
| Cross-Platform | Requires separate implementation per platform | One logic applies universally |
| Failure UX | Silent failure, operation rejected without prompt | Pop-up explaining reason, interactive correction |
3.2 Three Attack Surfaces of the Classifier
The risks of the Analyze-First route are concentrated in three areas:
- Prompt Injection: Inducing the model to generate seemingly normal commands, causing the review phase to give a low-risk score.
- Command Obfuscation: Hiding true semantics through encoding, environment variable concatenation, or indirect references.
- Novel Attacks: Patterns outside the training distribution of the review model, inherently lacking coverage.
Kernel-level isolation is physically immune to these three attacks—no matter how the upstream is induced, out-of-bounds syscalls will be rejected by the kernel. This is the fundamental advantage of “deterministic defense” over “probabilistic defense.”
3.3 Clear Trade-offs
The cost of deterministic defense is that implementations must be deployed per platform, incurring high maintenance costs; moreover, rejections are often silent, leaving users seeing “nothing happened,” making troubleshooting difficult. The cost of probabilistic defense is a capped safety strength, but it trades this for cross-platform consistency and explainability.
4. Dimension 2: Tool Systems
4.1 Two Perspectives on Tools
- Route A: Swiss Army Knife. Exposes only about a dozen general tools, the most critical being a sandbox-constrained Shell. File searching is left to the model to piece together command-line tools, and multi-file modifications are done in one go via a transactional patch interface. Few tools, low token overhead, coarse permission granularity.
- Route B: Professional Toolbox. Exposes over forty specialized tools: independent file matching, content search (built-in binary search), single-point file editing, command execution, web fetching and searching, sub-agent spawning, and Language Server Protocol (LSP) based code understanding tools. Each tool has clear inputs and outputs, observable structured results, and fine-grained permissions per tool.
4.2 Trade-off Matrix
| Dimension | Route A | Route B |
|---|---|---|
| Flexibility | High | Low |
| Reliability | Depends on user’s system environment | Self-contained dependencies, good consistency |
| Token Cost | Low | High (tool schemas consume context) |
| Observability | Low (Shell is a black box) | High (structured results) |
| Permission Granularity | Coarse | Fine (authorized per tool) |
5. Dimension 3: Context Cost and Scaling
Tool schemas themselves consume the context window. The parameter descriptions for forty-plus tools will continuously eat into the budget, squeezing out code context in long conversations; the dozen-tools approach leaves the budget for the code itself. However, the structured results returned by specialized tools are more compact, and retrieval tools usually save more tokens than letting the model write shell commands itself. Therefore, real cost needs to be measured by task type rather than concluded simply by tool count.
6. Dimension 4: Multi-Agent and Code Understanding
The Containment-First route tends to use “batch spawning of sub-agents” for parallel exploration, leaving scheduling to data-driven logic. The Analyze-First route tends to provide explicit sub-agent tools and language-service-level semantic understanding capabilities (go-to-definition, find references), replacing text guessing with structured semantics. The former scales well and is lightweight to implement; the latter offers higher precision in refactoring tasks within large codebases.
7. Dimension 5: Failure Modes and UX
Silent failures are acceptable in automated pipelines but offer a poor experience in interactive scenarios. Interactive approval is smooth during the exploration phase but will block in unattended CI environments. This dictates the natural use cases for each route.
8. Selection Decision Framework
if runtime environment is untrusted or requires unattended operation:choose Containment-First (kernel-level capability trimming + read-only/workspace-writable/fully-open tiers)elif interactive exploration or cross-platform consistency is prioritized:choose Analyze-First (classifier + path policy + approval)else:adopt a hybrid layered approach: kernel isolation fallback + semantic pre-review + full audit
9. Implementation Suggestions: Layered Defense
A more robust approach in production environments is layering rather than choosing one: use container platforms or sandbox runtimes to provide deterministic boundaries, restrict data exfiltration with read-only mounts and network egress policies, retain a complete command audit trail with logging services and monitoring alerts, place large build artifacts and datasets in object storage to fetch on demand, and decouple long-running tasks via message queues. Security strength is determined by the weakest link, so when “deterministic fallback + semantic pre-review + auditable trace” exist simultaneously, the overall risk is minimized.
10. Conclusion
Containment-First and Analyze-First are not a matter of superiority, but a mapping of constraints: Is the environment trusted? Is it cross-platform? Is it unattended? How large is the context budget? Answer that fundamental question first, and the rest of the design will naturally converge.
