Document Injection and AI Agent Host Boundaries: A Red Team Perspective

    This article examines how document injection can compromise the host boundaries of autonomous AI agents from a red team point of view. It breaks a typical agent system into five trust layers, traces the failure chain from untrusted external content to real host impact, and explains why long-term memory amplifies risk. It also clarifies what isolation can and cannot achieve, and shows how to move authorization outside the model through scoped tools, independent approval, two-stage execution, and separate outbound controls. Finally, it outlines repeatable red team testing, evidence-based incident handling, and the architectural principle that keeps a single bad suggestion from escalating into data leakage or host compromise.

    1. The Real Risk Is Not the Document Format, but How Permissions Are Chained

    Deploying an agent on a personal computer or a long-running server, and authorizing it to handle email, collaboration messages, files, and routine tasks, can significantly reduce repetitive work. But once the agent starts continuously ingesting external information, maintaining long-term memory, and autonomously invoking system tools, it is no longer just a text-generation interface. It becomes a software entity with real execution capability.

    At that point, the security question needs to be reframed: can an outside party who has no host account and no system credentials indirectly influence operations on the host, using only the content the agent reads?

    The answer is not “seeing a malicious document guarantees a takeover.” The risk materializes only when several conditions are met together: external content enters the model context, the model misreads it as an executable instruction, the execution layer performs no independent permission check, and the relevant tools can reach sensitive resources.

    So the essence of document injection is not that some markup syntax has special attacking power. It is that the system promotes “untrusted content” into “trusted control input.” Documents, emails, messages, attachments, and retrieval results can all become carriers of this problem.

    2. First, Draw the Trust Boundaries of the Agent System

    A typical autonomous agent can be split into five layers:

    1. External input layer: email bodies, group chat messages, web content, attachments, and other material submitted by participants.
    2. Context assembly layer: the concatenation and filtering of retrieval results, conversation summaries, task instructions, and runtime configuration.
    3. Model decision layer: understanding the task, proposing a plan, and generating tool-call requests.
    4. Tool execution layer: performing file reads and writes, network requests, message sending, and system commands.
    5. Persistent state layer: storing long-term memory, task progress, configuration, and authorization information.

    Each layer carries a different level of trust. A policy set by the system administrator and a sentence in an external email cannot gain the same control authority just because both end up as text.

    In particular: the fact that a model can understand an instruction does not mean that instruction carries any authorization. Identity authentication, permission checks, and execution approval must be handled by mechanisms outside the model.

    If a system relies only on the model “remembering not to obey strangers,” it turns a problem that should be solved by access control into a probabilistic semantic judgment.

    3. From External Content to Host Risk: A Typical Failure Chain

    From a defensive validation standpoint, the risk chain can be divided into five stages.

    3.1 Untrusted content enters the workflow

    To complete a legitimate task, the agent reads an email, a document, or a collaboration message. The attacker does not need direct access to the host; they only need to influence part of that content.

    The entry point usually has business legitimacy, such as “please organize the attachment,” “please verify the meeting notes,” or “please read the shared instructions.” This means that completely banning the reading of external content is unrealistic. What actually needs to be controlled is how the information is used after it is read.

    3.2 Content is mistaken for an operational requirement

    Malicious content may claim to be maintenance instructions, a security notice, or an added task condition, steering the agent away from its original goal.

    The core problem here is source confusion: the system fails to continuously preserve the semantic boundary that “this text came from external material,” so the model may treat requirements in the material as requirements from the user or administrator.

    Simply adding delimiters helps, but it does not constitute a complete defense. The model can still be influenced by text inside the delimited region, especially when the content is highly relevant to the current task.

    3.3 Influence spreads to persistent state

    If the agent can modify long-term memory or runtime instructions, a single wrong judgment may no longer be confined to the current session.

    For example, an incorrect rule from external material is written into long-term memory, and a later task retrieves that record and treats it as an established fact. Such contamination produces cross-session effects and keeps the risk alive.

    It is worth stressing that not all agents store core state in text files, and not all memory mechanisms read every record on each turn. Risk assessment should be based on the actual configuration, rather than generalizing one implementation into an inevitable trait of the whole technology category.

    3.4 The model proposes a high-risk tool call

    When a mistaken task understanding turns into a request for file access, outbound sending, or system execution, the risk moves from the cognitive layer into the operational layer.

    If the execution service accepts model requests unconditionally, the permissions the model actually obtains are equivalent to those of the tool process. At that point, even if the model itself has no system vulnerability, it can perform operations that should not be executed through legitimate interfaces.

    This is a failure of authorization design, not necessarily a traditional software exploit.

    3.5 Operations produce real-world consequences

    Possible outcomes include sensitive files being read, messages being sent incorrectly, the working directory being damaged, or background tasks being created without permission.

    But it is important to strictly distinguish between “the agent’s behavior was influenced,” “a tool was abused,” and “the host was fully taken over.” To conclude that the host is compromised, you must also confirm that the attacker actually obtained the corresponding execution capability, persistent control, or privilege escalation. You cannot claim the entire operating system is controlled merely because the model output dangerous text.

    4. Why Long-Term Memory Easily Becomes a Risk Amplifier

    Long-term memory improves the agent’s continuity, but it also introduces new data-integrity problems.

    A common mistake is converting “information that was once read” directly into “a rule to follow from now on.” An external message was originally just data to be processed; once written into a high-trust state, it can repeatedly influence later decisions.

    When memory is stored in text files, the files are easy to read and inspect, but that does not make them a security mechanism. Security depends on the following questions:

    • Who can write to these files;
    • Which directories ordinary tasks are allowed to modify;
    • Whether written content preserves its source;
    • Whether retrieval results distinguish facts, suggestions, and policies;
    • Whether state changes can be reviewed, rolled back, and attributed.

    Retrieval ranking is likewise not an authorization mechanism. Whether keyword-based or semantic, high relevance only means the content may be related to the question; it does not mean the content is true, trustworthy, or carries administrative authority.

    A recommendation is to divide state into at least three categories: policies maintained by administrators, preferences authorized by the user, and reference material from external sources. The three should use different write flows and access permissions, so they are not merged after retrieval into text with no source marker.

    5. What Isolation Can and Cannot Solve

    Virtual machines, containers, and separate runtime accounts can reduce the scope of the agent’s impact on the host environment. But the isolation boundary may still contain important data and valid credentials.

    If an isolated instance simultaneously holds access to private email, business files, and outbound network capability, then even if the attacker cannot escape, they can still cause data leakage or business loss.

    Persistent storage also retains contaminated state. Restarting the runtime process does not mean returning to a trusted state; if memory, configuration, or task records have already been altered abnormally, the risk may persist after the restart.

    Therefore, isolation should answer three concrete questions:

    • Which resources can the agent access;
    • What is the maximum loss a single erroneous operation can cause;
    • After an anomaly, can the system recover to a verifiable trusted state.

    “Running in an isolated environment” is not a conclusion, but one component of a defense system.

    6. Put Permission Control Outside the Model

    6.1 Do not open general system execution by default

    Many tasks only need to read a specified document, query a schedule, or send a draft, and do not require arbitrary system command execution.

    Prefer providing clearly scoped, structured tools. For example, “read a file in an authorized directory” is easier to constrain and audit than “execute an arbitrary command.”

    When system execution is genuinely needed, also limit the runtime identity, working directory, accessible resources, and task duration, and avoid using a high-privilege account long-term for the sake of convenience.

    6.2 Tool calls must pass independent authorization

    The execution layer cannot only check whether the request format is correct; it must also check the requesting principal, task scope, target resource, and side effects.

    The following is a conceptual flow, not any specific product interface:

    1. Tool request received
    2. → Verify session identity and authorized principal
    3. → Check whether the operation is within the current task scope
    4. → Validate the resource path and target address
    5. → Determine whether sensitive data or irreversible operations are involved
    6. → Obtain human confirmation when necessary
    7. → Execute in a restricted environment and log the result

    For file paths, also handle issues such as path normalization and link traversal, so that a request that appears to be inside an allowed directory does not actually reach another location.

    6.3 Use two-stage execution for high-risk operations

    Sending sensitive content externally, deleting data, modifying system configuration, and changing authorization should first generate a plan to be confirmed, then perform the operation.

    The confirmation interface must clearly show the target, content, scope of impact, and necessity. Merely asking “do you want to continue” is not enough to support an effective judgment.

    Approval should also be bound to the specific operation. Once a plan is confirmed, if the recipient, file scope, or execution content changes, it must be re-approved; a single approval cannot be extended into unlimited authorization.

    6.4 Set separate limits on outbound communication

    Allowing email reading should not automatically mean allowing email to be sent to any address; allowing the retrieval of public information should not automatically mean allowing local files to be uploaded.

    Set read permission, send permission, and network access scope separately. Outbound transfer of sensitive data should pass an independent rule check, rather than relying entirely on the model to judge “whether this address is trustworthy.”

    7. How to Conduct Repeatable Red Team Validation

    The goal of red team testing is not to prove that the model occasionally makes mistakes, but to verify whether an error can pass through control boundaries and produce actual side effects.

    Testing should be carried out in an authorized environment, using fictional accounts, synthetic documents, and worthless test data, to keep real credentials and private files out of the experiment.

    Recommended scenarios to cover:

    • Whether an external document can change the original task goal;
    • Whether a message from an ordinary participant can be mistaken for an administrator instruction;
    • Whether reference material can modify protected long-term state;
    • Whether the execution layer independently blocks the request when the model proposes an over-privileged call;
    • Whether a single approval can be reused for a different target or different content;
    • Whether abnormal state still affects later tasks after a restart;
    • Whether an abnormal tool call triggers alerts and evidence retention.

    Result records should distinguish three levels: whether the model was influenced, whether an over-privileged tool request was generated, and whether the tool actually executed successfully.

    This distinction is very important. If the model produces an erroneous plan but the execution layer successfully blocks it, the defense boundary has worked; conversely, if the model outputs nothing obviously abnormal, that does not prove the tool-permission design is sound.

    Test metrics can include the proportion of over-privileged requests, the proportion actually executed, human-approval interception, state-recovery completeness, and audit-chain integrity, but the test scope must be stated clearly, and local experimental results cannot be generalized into conclusions for all deployment environments.

    8. Incident Responsibility and Handling: Rely on Evidence, Not Guesswork

    Agent incidents often involve multiple stages: the deployer configures permissions, the application assembles context, the model proposes actions, the tool service completes execution, and an outside party provides input.

    Responsibility analysis must be based on the actual control capability of each stage, as well as applicable contractual terms and legal requirements, and cannot be simply attributed to “the model is unreliable” or “the user granted too much.”

    At a minimum, the following evidence should be retained:

    • The original task and its authorization scope;
    • The source, receipt time, and integrity information of external content;
    • Tool-call requests, parameters, and execution results;
    • Human-approval records;
    • Change history of sensitive state;
    • Relevant file-access and outbound-communication logs.

    Logs may also contain personal information; access should be restricted, a reasonable retention period set, and unnecessary credentials or sensitive bodies avoided in the records.

    After a suspected incident, first suspend high-risk execution capabilities and suspicious outbound channels, then preserve logs, verify state, and revoke credentials that may have leaked. Before restoring service, confirm that persistent state and configuration are still trustworthy, rather than just restarting the process.

    Conclusion: The Key to Security Is Making Errors Unable to Escalate

    The value of an autonomous agent comes from the combination of understanding, memory, and tool capability, and so does the risk.

    It is not surprising that a document can influence the model; what deserves real vigilance is that this influence is converted, without authorization validation, into an operation that holds real permissions.

    A reliable architecture should not hope that the model never misjudges. It should ensure that external content cannot self-authorize permissions, long-term memory cannot replace administrative policy, tool execution cannot bypass independent checks, and high-risk behavior can be blocked, audited, and recovered.

    When these boundaries are in place, even if the model is affected by prompt injection, the system has a chance to contain the problem as a single bad suggestion, rather than letting it escalate into data leakage or host compromise.