Isolated Runtimes and Prompt Injection Defense for General-Purpose AI Agents

    A general-purpose AI agent moves from answering questions to taking actions—reading files, running commands, and calling tools on your behalf. This shifts the cost of mistakes from wrong information to wrong actions, many of which are irreversible. This article explains how to reason about that risk: where the agent actually runs, under whose identity, and what it can touch; why allowlists alone are not security; how prompt injection exploits the fact that data and instructions look identical to a model; and how a three-condition model helps you break the chain of a successful attack. It closes with a hardening baseline for high-risk action confirmation, auditability, common friction points, and an acceptance checklist for measuring your security posture.

    1. From Answering to Acting: A Qualitative Shift in the Risk Model

    When a conversational model makes a mistake, the cost is usually just “wrong information”: the user can question it, verify it, or ignore it. A general-purpose AI agent works differently. You describe a goal in one sentence of natural language, and the agent decomposes the steps, calls tools, reads and writes files, accesses the network, and delivers a result. The moment a model is given filesystem access, command execution, network access, and credential-reading ability, the cost of a mistake shifts from “wrong information” to “wrong action”—and many of those actions are irreversible.

    This leads to a counterintuitive conclusion: the more valuable an agent is (the greater its autonomy and the more resources it can reach), the larger the expected loss of any single mistake. When evaluating these systems, the capability ceiling and the security floor have to be assessed together. Looking only at “what it can do for me” systematically underestimates the risk.

    A reality that is easy to overlook is cost. The combination of long context and multi-turn tool calls makes the inference and runtime overhead of a single task far higher than an ordinary conversation, so this capability is usually offered under higher-tier subscription plans or dedicated quotas. This also means teams should design “task templates” and “resource limits” before use—rather than opening up permissions first and bolting on boundaries later.

    2. Runtime Architecture: Where the Agent Runs, Under Whose Identity, and What It Can Touch

    It is clearer to break this kind of product into three layers:

    • Control plane / client: task description, authorization management, progress display, confirmation interactions;
    • Orchestration layer: model inference and tool-call decisions—deciding “what to do next”;
    • Execution layer: the isolated runtime that carries the actual side effects—commands, package management, file reads and writes.

    The security boundary is determined almost entirely by three questions about the execution layer:

    1. Where does it run—a host process, an OS-level container, or a lightweight virtual machine?
    2. Under whose identity does it run—reusing the user’s or developer’s high-privilege identity, a restricted identity, or a one-time identity?
    3. What can it reach—mount scope, outbound network, and credential scope.

    The engineering differences among three isolation models:

    • Running directly in the host process: shares the filesystem and user permissions, so a single misoperation affects all personal data. Not suitable as the default form for a general-purpose agent.
    • OS-level containers: isolate views through namespaces and reduce privileges through capability trimming; fast to start and cheap to run. But they share the host kernel, so a kernel-level vulnerability becomes an escape surface.
    • Lightweight virtual machines: a separate kernel with hardware-assisted virtualization raises the bar for escape significantly. The cost is startup overhead and image management complexity.
    • Combined form: virtual machine + filesystem snapshots + egress proxy, gaining both rollback and audit capability at the same time. This is currently the more solid engineering baseline.

    There is a key engineering fact here: when the agent runs a destructive command like “recursively delete all files” inside a virtual machine’s filesystem, the blast radius is contained within that instance, and the host system and the user’s other data are unaffected. This is exactly the substantive difference between a “true isolated runtime” and a “shell with a sandbox toggle.” To judge whether a solution actually has isolation, you should ask about the escape assumption and the blast radius—not whether there is a sandbox option on the configuration screen.

    An illustrative configuration (to show the shape, not a specific product interface):

    1. runtime:
    2. isolation: micro-vm # process | container | micro-vm
    3. identity: agent # non-privileged identity; never reuse a developer's long-lived credentials
    4. filesystem:
    5. mounts:
    6. - host: ./workspace/in
    7. target: /ws/in
    8. mode: ro # read-only by default
    9. deny: ["~/.config", "~/.ssh", "credential_store/"]
    10. network:
    11. default: deny
    12. allowlist: ["package-mirror.internal"]
    13. audit: all # full logging of all egress
    14. resources:
    15. cpu: "2"
    16. memory: "4Gi"
    17. timeout: "30m"
    18. rollback:
    19. snapshot: enabled # full rollback on task failure or privilege violation

    3. Network and Files: Allowlists Narrow the Surface, They Are Not Security

    Denying outbound traffic by default and allowing only package-manager source domains is the mainstream approach for these agents, and it blocks a large amount of random external connections. But allowlists have three known weaknesses that must be considered at design time:

    • General-purpose hosting domains: code hosting, note-taking, image hosting, and pastebin-style services are often used by the agent itself. Once they are on the allowlist, they become an extremely low-cost data exfiltration channel—simply stitch sensitive content into a commit message or a gist.
    • Install-time code execution: package managers allow running install hooks / build scripts, which effectively opens arbitrary code execution on a “legitimate domain.” Combined with dependency poisoning or a squatted package of the same name, an attacker can escalate from an allowlisted channel to arbitrary command execution, and the meaning of the allowlist is completely negated.
    • DNS channels: as long as domain resolution is allowed, there exists a theoretical channel for low-speed, covert exfiltration through query records.

    So for outbound traffic, “domain filtering” alone is not enough; you need a combination of content-level and volume-level constraints: domain + request rate + per-transfer byte threshold + sensitive-feature detection (token formats, private-key headers, internal addresses, bulk structured data). Any single dimension that matches should block and alert.

    File access follows the same principle of “explicit over default”:

    • Explicit mounts with read-only by default; grant write permission per directory, not per instance.
    • Watch for link traversal: symlinks, hardlinks, and mount points can turn a “read-only directory” into a writable target.
    • Hidden files and metadata are the most frequently overlooked channels: version-control directories, editor configs, extension directories, and cache directories can all hold tokens, so the allowlist should explicitly exclude them rather than relying on a path “looking harmless.”

    4. Prompt Injection: The Root Cause Is That Data and Instructions Are Isomorphic

    Definition: prompt injection occurs when the model treats text from untrusted content as instructions to execute.

    • Direct injection: the user input itself is the payload. Relatively easy to defend against; can be mitigated through input detection and intent clarification.
    • Indirect injection: the payload is hidden inside third-party content the model will read—web pages, documents, ticket bodies, comment sections, code comments, logs, text inside images, file metadata. This kind of injection is the most dangerous, because the user is unaware the whole time.

    Common hiding techniques include: small text in the same color as the background, zero-width characters, source-code comments, invisible rendering layers, text inside images, document metadata fields, and stacked blank layers. The human eye cannot see them, but the text-extraction pipeline will ingest them all.

    The root cause lies at the representation layer: in traditional software there is a clear boundary between “code” and “data,” and parameterized queries separate instructions from data during database access, which fundamentally eliminates injection-class vulnerabilities. In a large model, however, the text entering the context is isomorphic in representation, and the model has no reliable “trust label” mechanism to distinguish system instructions, user instructions, and tool-returned content.

    This yields two inferences:

    • Writing a line in the prompt like “don’t listen to the file” cannot cure it. Prompt constraints are probabilistic and get overridden when they meet a more specific, more system-toned fake instruction.
    • The realistic goal is not to eliminate injection, but to decouple “injection succeeding” from “causing harm”: accept that injection will happen, and drive the expected payoff of injection toward zero.

    5. The “Three-Condition” Disaster Model

    A substantive leak or destruction usually requires three conditions to hold at the same time:

    1. Reachability: the agent can read valuable data or perform irreversible actions;
    2. Controllable input: the agent reads content an attacker can write (web pages, documents, code, tickets);
    3. Exfiltration channel: the result can leave the isolation boundary (a network egress, a writable shared directory, an outbound-sending tool, or an artifact readable externally).

    The engineering strategy becomes clear from here: do not pile all the investment onto “perfectly detecting injection.” Instead, make “breaking any one link” the default design goal.

    • Break link 1: sensitive data does not enter the context, credentials are not stored on disk in mounted directories, and authorization is minimized and time-limited.
    • Break link 2: before external content enters the context, explicitly mark it as untrusted data and store it separately from its summaries and instructions.
    • Break link 3: default to no network or an extremely narrow allowlist, combined with volume thresholds and sensitive-feature detection.

    If any one of the three links is reliably sealed off through engineering means, then even if the injection success rate is not zero, an incident is hard to escalate into a disaster.

    6. Interaction Layer: High-Risk Actions Need “Grading + Revocability + Auditability”

    It is advisable to classify the following actions as irreversible / high-risk, force a second confirmation by default, and show the plan and blast radius rather than a post-hoc report:

    • Bulk delete, overwrite, or move of files;
    • Reading or exporting credentials, tokens, private keys;
    • Outbound sending: submissions, publishing, messages, forms;
    • Modifying permissions, network policies, or startup items;
    • Executing install-time scripts.

    Four accompanying points: provide a readable diff preview and an impact-scope list before the action; make authorization one-time and short-lived, revoked as soon as the task ends; enable snapshots or versioned storage in the workspace so actions can be rolled back; and keep full logging (input, tool calls, parameters, return summaries, elapsed time), with circuit-breaker rules set—pause immediately and escalate to human confirmation when a high-risk sequence like “read sensitive directory → encode and package → attempt exfiltration” is detected.

    7. The Responsibility Mismatch: A Statement Cannot Replace Secure Defaults

    These general-purpose agents target non-technical users, yet the risk list above requires the user to have threat-modeling ability. If security responsibility is only pushed down in the form of a disclaimer, the actual result is that the people least able to recognize the risk bear it. A workable alternative path:

    • Secure defaults by default: no network, read-only mounts, no credentials, with capabilities granted temporarily per task;
    • Block high-risk actions up front rather than reminding with a pop-up after the fact;
    • Guide with tangible examples: demonstrating a hidden-text injection once is more effective than ten lines of warning text;
    • Establish a unified baseline at the organizational level: have the platform, not the individual, take on the hardening responsibility.

    On the platform-based implementation approach, a common combination is to use a container platform to carry the isolated runtime, object storage to hold workspaces and snapshots, a logging service to centrally collect session and tool-call records, and monitoring/alerting to connect to abnormal-egress detection. Cloud platforms such as Baidu AI Cloud provide exactly these general-purpose capability categories; the value lies in converging “each member hardening on their own” into “one unified security baseline with centralized auditing,” rather than replacing the user’s task design.

    8. Typical Friction Points in Actual Use

    Putting these agents into a daily workflow, the common friction is concentrated in six places—understanding them is more useful than remembering marketing points:

    • Environment setup failure: dependencies fail to install because of domains outside the allowlist, and the task degrades or stalls midway. Countermeasure: pre-build images and offline package sources.
    • Insufficient permissions: writes are rejected under read-only mounts. Countermeasure: grant elevated permissions explicitly per directory, rather than opening up everything.
    • Context drift: the task deviates from the initial intent in the later stages. Countermeasure: set staged checkpoints and require intermediate conclusions for confirmation.
    • Confirmation interrupting the pipeline: automation is cut off by human confirmation. Countermeasure: pre-declare a release scope for low-risk actions and keep confirmation for high-risk actions.
    • Cost and quotas: the overhead of long context limits the task. Countermeasure: split tasks, trim the context, and cap the number of turns.
    • Poor reproducibility: after a one-time container is destroyed, the problem is hard to review. Countermeasure: retain logs, snapshots, and minimal reproduction inputs.

    9. Acceptance Checklist: How to Quantify Your “Security Level”

    • Injection test set: hidden text, zero-width characters, document metadata, text in images, cross-session contamination, and tool-return injection—measure block rate and false-rejection rate for each;
    • Permission matrix: access attempts to unmounted paths, non-allowlisted domains, and credential directories should all fail and be auditable;
    • Blast-radius test: run destructive commands inside an isolated instance and verify the host and shared resources are unaffected;
    • Coverage of high-risk action confirmations and a count of bypass attempts;
    • Rollback capability: mean time to recovery and data-consistency verification results;
    • Egress monitoring: hit rate and latency of abnormal-exfiltration detection.

    10. Conclusion

    The core engineering proposition of a general-purpose AI agent is not model capability but boundary design: where it runs, under whose identity, what it can touch, and whether it can be rolled back and held accountable after an incident. The isolated runtime determines the blast radius; the allowlist plus content-level egress control determines the exfiltration channel; graded confirmation and full auditing close the accountability loop; and injection evaluation guarantees regression safety. Only by making these four things the default baseline can these tools move from “impressive in a demo” to “trustworthy for everyday use.”