Analyzing the Security Architecture and Threat Models of Agent Execution Frameworks
As Large Language Models (LLMs) evolve from simple chatbots into autonomous agents capable of calling APIs, executing commands, and writing code, they introduce unprecedented security challenges. This article explores the security architecture and threat models of typical agent execution frameworks. It covers the semi-trusted entity assumption, plugin-centric organization, event sourcing, layered sandboxing, and potential blind spots, providing a practical reference for designing secure AI agent systems.
1. Introduction: Security Challenges in Agent Execution Frameworks
With the deepening interaction between Large Language Models (LLMs) and external tools or environments, agents have evolved into “digital employees” capable of autonomously calling APIs, executing commands, reading and writing files, and even writing code. This capability leap brings unprecedented security challenges: a model induced by malicious web pages, compromised repository contents, or forged documents may execute dangerous operations, leak credentials, or even completely compromise the host machine. Therefore, designing an execution framework (Harness) that explicitly constrains model behavior boundaries, ensures auditability, and adheres to the principle of least privilege has become a critical topic in AI engineering.
This article will conduct a technical analysis based on a typical “everything is a plugin” agent execution framework design, exploring four dimensions: threat model, architectural components, security mechanisms, and potential limitations, to provide a referenceable security design paradigm.
2. Threat Model: The Semi-Trusted Entity Assumption
Any security design begins with a clear definition of attackers and trust boundaries. This framework treats the model as a “semi-trusted entity,” which means:
- The model itself is not entirely malicious, but its reasoning results can be polluted by external inputs—for example, through Prompt Injection techniques that allow malicious web content to override system instructions, or README files in repositories to induce the model to perform unexpected operations.
- The model may exhibit “unintentional malice” when processing untrusted data, meaning it might follow attacker-implanted instructions or misinterpret ambiguous commands.
- The security goal is clear: The attacker’s ultimate goal is to achieve Remote Code Execution (RCE) on the host machine or steal credentials stored in the environment (such as SSH keys or cloud service tokens). The framework must ensure that even if the model is completely “deceived,” it cannot break through the established permission boundaries.
Based on this threat model, the core philosophy of all protective measures is: Do not trust the model’s intent; trust only explicit permission declarations and verifiable execution traces.
3. Architecture Design: Plugin-Centric Organization
1. The Plugin Tree: Everything is Configurable
The framework abstracts model adapters, tool registries, session logs, and even the Agent main loop itself as plugins. This design brings two key advantages:
- Flexibility in composition and replacement: Developers can choose different plugin combinations based on different scenarios (e.g., coding assistant, data analysis, browser operation), and even hot-swap modules without affecting the whole.
- Explicit capability boundaries: Each plugin explicitly declares its minimum required permission set, which the framework uniformly validates upon loading, preventing implicit privilege escalation.
For example, a file operation plugin must explicitly declare its accessible directory scope, while a network request plugin must declare a list of allowed domains. This declarative design provides a foundation for static analysis in security audits.
2. Event Sourcing: Logs as Truth
The framework adopts an append-only event log mechanism, whose core principle is “everything the model sees must be reconstructable from the logs.” This means:
- Every time the model reads a file, calls a tool, receives user input, or generates output, an immutable log record is created.
- Logs record not only the results but also the context: including complete input parameters, environment variables, timestamps, and call chain IDs.
- Any “replay” operation (such as replaying a historical session) must be based on these logs and cannot directly access memory or disk state.
The value of this mechanism lies in auditability and reproducibility. When a security incident occurs, the security team can trace every step of the model’s decision-making basis like reviewing a dashcam, quickly locating which external input caused the abnormal behavior. At the same time, it prevents the model or plugins from hiding operations by modifying internal state.
3. Capability Seams: The Service / Provider / Consumer Triad
To balance extensibility and control, the framework defines a standard capability seam pattern:
- Service Definition: Describes the abstract interface of a capability, including input/output types, error handling, and audit hooks.
- Provider: The specific execution backend that implements the service definition, such as a Shell executor, an HTTP client, or a database connector.
- Consumer: The plugin or model adapter that calls the service; it can only see the Service Definition and cannot directly access the Provider’s internal implementation.
This three-role isolation ensures that each capability has independent lifecycle management and security policies. For example, a “code execution” service can be individually configured with timeout, resource limits, and privilege downgrading policies without affecting other services.
4. Layered Sandbox: From System Calls to File Systems
The sandbox is the last line of defense in the security architecture. The framework employs a layered sandbox strategy, where each layer is responsible for constraints in different dimensions:
- Process-level sandbox: For command execution like bash, system call filtering (such as Landlock or Seatbelt mechanisms) or container wrapping (like bwrap) is used to restrict the system calls, network access, and file paths the process can initiate. Thus, even if the command itself is injected with malicious code, it cannot break through kernel-level restrictions.
- Filesystem fencing: A “filesystem gatekeeper” is implemented within the process, forcing all read and write operations to occur within a preset working directory (e.g., /workspace). This gatekeeper is implemented by intercepting system calls or hijacking standard libraries, without relying on external containers.
- Three-tier permission modes: The framework provides three explicit permission granularities:
read-only: Only allows reading specified directories; no write operations are permitted.workspace-write: Allows creating, modifying, and deleting files within the dedicated workspace directory, but cannot touch other paths.danger-full-access: Completely lifts restrictions, used for trusted local debugging or non-sensitive tasks.
This tiered mode allows deployers to flexibly choose based on task trust levels, reflecting the “least privilege” principle.
5. Dynamic Plugins: The Security Paradox of Model Self-Extension
The most radical design allows the model to write code and mount it as a new plugin through specific tools (e.g., define_plugin and run_plugin). This greatly enhances the agent’s adaptive capability—the model can generate specialized tools for new problems. However, it also introduces significant risk: the code generated by the model itself might be malicious (indirectly from an attacker). Therefore, the framework provides two key constraints:
- VM isolation: Plugins generated by the model run within a lightweight virtual machine (such as
node:vm), which lacks direct access to the host filesystem, network, or processes. - Guard Facade: Plugins within the VM can only call external services through a strictly filtered facade object. This facade enforces parameter validation, limits call frequency, and logs all calls. Any attempt to bypass the facade to directly use Node.js core modules will be intercepted and throw an error.
The philosophy of this design is: Let the model “create freely,” but all creative outputs must run inside a “transparent safe.” The key to the safe (the facade) is held by the framework, not the model.
4. Security Evaluation: Practical Feasibility and Potential Blind Spots
1. Protection Effectiveness Analysis
- Against Prompt Injection: The event sourcing mechanism makes the injection source clearly distinguishable, and the layered sandbox limits the scope of harm that can be executed post-injection. For example, even if the model is induced by a malicious web page to execute
rm -rf, due to process sandbox restrictions, this command can only affect files within the workspace and cannot delete critical host paths. - Against Credential Leakage: The permission modes strictly require the model to send data only through restricted network interfaces, and target domains must be on a whitelist. If an attacker attempts to have the model read
/.ssh/id_rsaand exfiltrate it, the filesystem fence will prevent the read (because the path is not in the workspace), or the network layer will block the connection. - Against Dynamic Code Escape: VM isolation can effectively stop most attempts, but historically, the
vmmodule itself has had escape vulnerabilities (e.g., through Proxy construction or anomalous prototype chains). Therefore, this framework must also be paired with strict dependency monitoring and version locking.
2. Potential Blind Spots and Improvement Directions
- Semantic vulnerabilities: Sandboxes can restrict system calls but cannot recognize “semantically malicious” operations. For instance, the model might be induced to send a “delete all users” request to a legitimate API. This does not violate filesystem or network rules but can cause business loss. Therefore, business-level audit policies need to be added, such as secondary confirmation for operations by specific tools.
- Log flooding attacks: Attackers might generate massive logs to obscure malicious operations or cause storage exhaustion. The framework needs to implement log size limits, sampling strategies, and anomaly pattern detection.
- Environment variable and configuration injection: When the model reads environment variables via tools, it might be induced to output sensitive values. It should be ensured that environment variables do not contain real credentials, but are indirectly injected via one-time tokens or Key Management Services.
- Composable security: While the plugin system is flexible, the overall security of a combination might be greater than the sum of its parts. For example, a read-only plugin combined with a network plugin might form an implicit “read file -> exfiltrate” channel. Therefore, the framework should support composable security analysis, such as dynamically calculating the combined permission scope of all plugins.
5. Practical Recommendations: How to Build a Secure Agent Execution Framework
Based on the above analysis, the following practical points can be summarized:
- Fail by default: Any permission not explicitly granted is denied; it is better to have limited functionality than relaxed constraints.
- Logs are the law: Ensure that all model-visible states (including system prompts and tool outputs) are written to immutable logs, and the replay mechanism must rely entirely on the logs.
- Least privilege decomposition: Break down large, comprehensive tools into fine-grained services, with each service exposing only necessary operations.
- Human-in-the-loop working mode: Set up interception points requiring “manual approval” for dangerous operations, especially those involving deletion, batch writing, or data exfiltration.
- Continuous security testing: Regularly use red team attacks (e.g., deliberately injecting malicious instructions) to verify the framework’s resistance and update sandbox rules accordingly.
6. Conclusion
The agent execution framework analyzed in this article represents a pragmatic security design approach oriented towards “semi-trusted models.” By building multiple lines of defense through plugin organization, event sourcing, capability seams, layered sandboxing, and controlled dynamic extension, it ensures that even if the model is maliciously attacked, its impact is suppressed within a very limited, auditable, and rollback-able space. No security system can guarantee absolute security, but this framework provides a replicable and evolvable methodology, offering a crucial foundational guarantee for the large-scale deployment of AI Agents. For developers, the key is to understand its threat model assumptions and customize permission strategies based on actual business scenarios—security is not a static lock, but a continuous closed-loop process.
