AI Coding Agent Architectures Compared: Containment-First vs. Analyze-First
This article compares two dominant AI coding agent architectures—containment-first and analyze-first—and shows how a single trust assumption drives downstream choices in security, tool design, context cost, observability, extensibility, and user experience. It explains the deterministic guarantees of kernel-level sandboxing versus the semantic flexibility of classifier-based review, outlines the trade-offs of minimal command primitives versus structured tool sets, and offers scenario-based selection guidance along with a practical layered approach.
Introduction: The Real Divide Is Trust, Not Capability
AI coding agents are shifting roles: from passive helpers that autocomplete code snippets into autonomous executors that can read files, modify code, run commands, and access the network. Once an agent can act, the engineering focus moves from “is the generated code correct?” to “is the execution safe?”
Two common architectures in the industry can be summarized in two phrases: containment first and analyze first. The former assumes the model may fail or be manipulated at any time, so it uses the operating system kernel to restrict what can be done. The latter assumes the model can be reviewed, so it adds an extra model or rule layer to decide whether each operation should be allowed.
The key insight is that this is not a set of seven or eight independent feature trade-offs, but a chain of consequences triggered by one fundamental choice. Once the trust assumption is fixed, the security mechanism, tool granularity, prompt cost, observability, cross-platform strategy, and even user experience all follow from it.
1. The Core Framework: How Do You Keep AI Command Execution Safe?
All the differences come down to one question: how do you ensure safety when an AI executes commands?
- Route A (containment first): Do not trust model behavior; trust the kernel’s deterministic interception. Capability boundaries are enforced by the operating system, and the model can only operate within an authorized “fence.”
- Route B (analyze first): Do not fully trust the model, but do not rely on the kernel either. Instead, an “AI reviews AI” classifier scores each proposed action, combined with path allow/deny lists and interactive approval.
This answer determines every subsequent design decision. Understanding it matters more than memorizing any feature comparison table.
2. Dimension 1: Deterministic Differences in the Security Model
The typical containment-first implementation is a kernel-level sandbox: on Unix-like systems, it combines mandatory access control with system call filtering; on desktop systems, it uses the built-in sandbox framework; in restricted environments, it uses process-level token de-escalation. The common point is that interception happens in the kernel and does not depend on whether the model’s judgment is correct.
The typical analyze-first implementation is a classifier plus multiple permission layers: commands are scored semantically, combined with path rules and human confirmation. Its interception happens in “a layer of software judgment before execution,” so its security ceiling is limited by the classifier’s coverage.
This leads to three verifiable engineering properties:
- Bypass resistance: Kernel interception is deterministic; a classifier can be bypassed by writing patterns it has never seen.
- Failure experience: Containment often results in silent rejection (the operation is blocked without explanation); analysis usually shows a dialog explaining the reason, which is friendlier to interact with.
- Cross-platform cost: Containment requires separate implementation and testing on each platform; analysis is largely universal with one set of logic.
Three common attack surfaces of the classifier route deserve separate emphasis:
- Prompt injection: Tricking the model into generating malicious commands that “look ordinary”;
- Command obfuscation: Writing patterns that distort semantics through encoding, variable concatenation, indirect invocation, and so on;
- Novel attacks: Patterns outside the coverage of training and rules.
Kernel fences have a “physical immunity” to out-of-bounds behavior in the first two categories—no matter how the upper layer tries to induce it, unauthorized actions are rejected by the kernel. This does not mean containment has no risk (destructive operations within authorized scope still need business-layer protection); rather, its security floor is higher and more predictable.
3. Dimension 2: The “Swiss Army Knife” vs. the “Professional Toolbox”
The security model directly determines tool design.
Containment tends toward minimal but powerful primitives: one sandbox-constrained command execution entry point, plus a whole-patch mechanism that supports multi-file, transactional changes; file search is left to the model to organize commands itself. There are few tools, and the model has to “assemble commands on its own.”
Analyze-first tends toward a rich, structured toolset: file location, content retrieval, targeted editing, command execution, network access, code semantic understanding, and so on, each independent with clear inputs, outputs, and permission boundaries.
The costs of the two approaches can be compared quantitatively:
| Dimension | Containment (Option A) | Analyze-First (Option B) |
|---|---|---|
| Flexibility | High | Lower |
| Reliability | Depends on the host environment | Bundled dependencies, good consistency |
| Token cost | Low | High (tool descriptions consume context) |
| Observability | Low (black-box commands) | High (structured results) |
| Permission granularity | Coarse | Fine (per-tool authorization) |
It is worth emphasizing that the “high/low” in the table are architectural tendencies, not absolute superiority. Structured tools make auditing, replay, and fine-grained authorization easy; a unified command entry point means long-tail tasks are hardly limited by the tool list.
4. Dimensions 3–6: Context Cost, Observability, Extensibility, and User Experience
Context cost: The more tools there are, the more context budget the tool descriptions themselves consume, compressing the space left for code and reasoning; a command-style entry point saves this budget, but at the cost of the model possibly generating lengthy commands and repeatedly trial-and-error.
Observability: Structured tools naturally produce parseable logs, making auditing and replay easy; a command-style entry point requires additional command parsing and normalization to achieve the same observability.
Extensibility: Adding a capability is “adding a tool” in the toolbox model; in the command entry point model, it often requires “zero changes,” because the host environment already provides the new command.
User experience: Analyze-first is more transparent in the “request—explain—approve” loop; containment is quieter, but it needs to feed rejection reasons back to the model so it can adjust its strategy on its own; otherwise, it is prone to “repeatedly hitting walls.”
5. Selection Guidance: Match by Scenario, Not by Finding a “Stronger Side”
- High compliance, lots of untrusted input, need for a deterministic security floor: prioritize containment, combined with least privilege and operation auditing.
- Need for fine-grained authorization, structured auditing, and a consistent cross-environment experience: prioritize analyze-first, and continuously counter prompt injection and command obfuscation.
- A pragmatic compromise: use containment as the inner safety net and analysis on the outer layer to improve experience, i.e., a three-layer stack of “deterministic interception + semantic review + human confirmation.”
Whichever route you choose, it is advisable to solidify the following engineering practices: default least privilege, tiered authorization by task, mandatory confirmation for high-risk actions, complete replayable execution traces, and in the cloud, use general-purpose logging services, monitoring and alerting, object storage, and container platforms to carry auditing and isolation capabilities.
Conclusion
The divide between containment first and analyze first is essentially a trade-off between “deterministic security” and “semantic flexibility.” Think through your trust assumption first, then derive tools, cost, and experience, and the architecture will not keep wavering over details.
