Sandbox-First vs. Analysis-First: Two Security Philosophies for AI Coding Agents

    This article examines two contrasting security architectures for AI coding agents: kernel-level sandboxing (sandbox-first) and LLM-based command review (analysis-first). It traces how this root choice cascades into tool design, permission models, user experience, and token costs; compares deterministic interception with probabilistic review; and offers practical guidance for selecting or building agents, including hybrid defense-in-depth approaches.

    AI coding agents are becoming part of developers’ daily workflows, but different agents have evolved diametrically opposed technical paths for the question of how to let AI execute commands safely. One path proposes using OS kernel-level sandboxes to physically fence in what AI can do. The other proposes using another AI—usually an LLM classifier—to review every action the AI takes. This root divergence cascades like falling dominoes into downstream decisions about tool design, permission systems, user experience, and even token costs. This article abstracts the design philosophies behind these two architectures, analyzes their strengths, weaknesses, and suitable scenarios dimension by dimension, and helps readers make more reasonable architecture decisions when selecting an agent or building one in-house.

    1. The Core Question: How Do We Ensure Safety When AI Executes Commands?

    One of the core capabilities of AI coding agents is executing commands in the terminal on behalf of developers: reading files, writing code, running tests, and installing dependencies. But once these operations get out of control, the consequences range from damaging the workspace to leaking data or deleting system files. Therefore, every agent architecture must answer the same fundamental question: how do we ensure safety when AI executes commands?

    The industry currently has two representative answers:

    Option Philosophy Plain-language view
    Use the OS kernel to limit what AI can do Sandbox-first Do not trust the model; build a wall first
    Use an LLM classifier to review what AI wants to do Analysis-first Do not fully trust the model; let AI supervise AI

    The key point is that this is not seven or eight independent design decisions, but a chain reaction triggered by one root choice. Once sandbox-first is selected, the tool system naturally tends toward minimalism. Once analysis-first is selected, the tool system naturally moves toward a refined, specialized toolbox. Let us unpack this layer by layer.

    2. Security Model: Deterministic Interception vs. Probabilistic Review

    2.1 Sandbox-First: Kernel-Level Sandboxing

    The core idea of this type of solution is: no matter what the model “wants” to do, it “cannot” perform out-of-bounds actions at the operating system level. Common implementation paths include:

    • macOS: use the system’s built-in sandboxing mechanisms, such as Seatbelt-like policy frameworks, with declarative profiles to restrict a process’s file system and network access;
    • Linux: combine mechanisms such as Landlock for file access control, seccomp for system call filtering, and bubblewrap for namespace isolation;
    • Windows: run child processes with restricted tokens.

    Typical operating modes usually fall into three tiers:

    1. read-only # read only; all writes forbidden
    2. workspace-write # write only to the current workspace; network restricted by default
    3. danger-full-access # fully open; user assumes the risk

    This architecture has very high bypass resistance—it is kernel-level deterministic interception. No matter how the AI is induced by prompts, out-of-bounds operations will be directly rejected by the operating system. But the costs are also obvious:

    1. High cross-platform cost: each operating system requires a separate sandbox implementation;
    2. Silent failures: when an operation is rejected by the sandbox, the AI often sees only a vague error code. It may not understand “why it failed,” leading to repeated retries or incorrect fallback plans.

    2.2 Analysis-First: AI Reviews AI

    The other type of solution does not rely on kernel isolation. Instead, it builds a multi-layer permission system:

    • Path allow/deny lists: declare which directories can be read and written;
    • LLM classifier: assign a safety score to every command the AI wants to execute and determine whether it is malicious;
    • Interactive approval: when the score is uncertain or the operation is sensitive, show a dialog box for a human to decide.

    Its advantages are that one codebase works across platforms—the classifier runs at the application layer and does not depend on system features—and that user experience is better: when execution is denied, the reason is clearly explained, and the AI can adjust its strategy accordingly.

    But the cost is the introduction of three types of attack surfaces:

    1. Prompt injection: malicious content hidden in web pages or code comments induces the model to generate malicious commands that “look normal”;
    2. Command obfuscation: techniques such as base64 encoding, environment variable concatenation, and nested pipes make it difficult for the classifier to identify the real intent;
    3. Novel attacks: patterns the classifier has never seen during training naturally carry a risk of missed detection.

    In other words, the lower bound of the defense for analysis-first solutions depends on the correctness of the classifier’s judgments, which is probabilistic. The lower bound for sandbox-first solutions is guaranteed by the kernel, which is deterministic.

    3. Tool System: Swiss Army Knife vs. Professional Toolbox

    3.1 Two Design Philosophies

    The tool system of the sandbox-first path is usually minimal: it provides only about a dozen basic tools, with a sandboxed shell at the core. Need to search files? Let the model compose an rg command itself. Need to access a web page? Let the model run curl. File editing tends toward a transactional patch mechanism—generate multi-file diffs at once, apply them as a whole or roll them back as a whole, similar to patch semantics in version control.

    The analysis-first path moves toward a professional toolbox: the number of tools can reach dozens, and each tool has a clear input/output schema.

    • File search: packaged global matching and content search tools, typically with a bundled search-engine binary and no dependency on the user’s environment;
    • File editing: a single-point precise edit tool that changes only one place at a time, with permission granularity down to “each file operation”;
    • Web access: dedicated web scraping and search tools that return structured results;
    • Code understanding: integration with the Language Server Protocol (LSP), giving the model semantic capabilities such as go-to-definition and find-references;
    • Multi-agent collaboration: tools for spawning sub-agents, enabling task decomposition.

    3.2 Cost Comparison

    Dimension Minimal shell (Option A) Professional toolbox (Option B)
    Flexibility ✅ High; the model freely composes commands ❌ Low; limited to the tool list
    Reliability ❌ Depends on what is installed on the user’s system ✅ Bundled dependencies; works out of the box
    Token cost ✅ Low; few schemas ❌ High; dozens of tool definitions consume context
    Observability ❌ Low; the shell is a black box ✅ High; structured results are easier to audit
    Permission granularity ❌ Coarse; can only control the entire shell ✅ Fine; per-tool, per-file authorization

    There is no absolute winner here. Option A bets that “the model is smart enough to solve environment differences on its own.” Option B bets that “structured constraints make behavior more predictable and auditable.”

    4. Engineering Perspective: How to Choose or Build In-House

    4.1 Selection Recommendations

    • High security sensitivity—production operations, corporate intranets, sensitive data: prioritize sandbox-first architectures. The determinism of kernel-level isolation is something no classifier can promise.
    • High cross-platform consistency requirements and emphasis on transparent interaction: analysis-first architectures have lower deployment costs—no platform-specific code—and provide a friendlier human-AI collaboration experience.
    • Hybrid approaches are emerging: more and more implementations use a two-layer design of “classifier for initial screening + sandbox for fallback,” using the analysis layer for explainability and user experience, and the sandbox layer to cover extreme risks.

    4.2 Architecture Lessons for Building Your Own Agent

    If you are building your own coding agent, you can borrow the following principles:

    1. Decide the security philosophy first, then design the toolset. The security model is the “root decision.” The tool system and permission system should be derived from it. Avoid self-contradictory designs such as “dozens of network-requiring tools running inside a sandbox.”
    2. Do not over-trust classifiers. Any LLM-based review should assume it can be bypassed. Critical operations must have a deterministic barrier—even a simple path-prefix check.
    3. Transactional editing is better than fragmented editing. Atomic multi-file modifications with rollback mechanisms can significantly reduce the risk of AI damaging the codebase.
    4. Make failures explainable. Whether the denial comes from the kernel or a classifier, return structured denial reasons to both the model and the user, avoiding silent failures that lead to ineffective loops.
    5. Control the context cost of tool schemas. The more tools there are, the longer the system prompt and the higher the inference cost. Tool subsets can be loaded dynamically by task stage.

    5. Conclusion

    Sandbox-first and analysis-first are essentially two technical bets: “trusting the kernel” and “trusting intelligence.” The former accepts higher cross-platform engineering cost and a less polished user experience in exchange for a deterministic security boundary. The latter accepts weaker adversarial robustness and higher token cost in exchange for flexibility and explainability. Understanding this “root decision—chain reaction” derivation chain is more valuable than memorizing the feature list of any specific product, because no matter how tools evolve, this underlying philosophical tradeoff will persist. In practical engineering, the most robust choice often acknowledges that each philosophy has blind spots and combines deterministic fencing with intelligent review to form defense in depth.