6 min
LLM data security: Protecting data when agents run code
Agents mix reasoning, tool use, and code execution in one session. Traditional security can't inspect what happens inside. Learn how to close the gap.

Your AI agent works in staging. It parses customer documents and generates Python scripts that it correctly executes for analytics reports.
Then a security review finds the agent can read files outside its workspace, which is a sandbox escape. A prompt injection test also shows it can exfiltrate data through its own API tools, with no credential theft required.
The agent logic is sound, but the security architecture underneath isn't built for agent behavior. Agents mix reasoning, tool use, and code execution in one session. They chain decisions based on natural language input.
Traditional security tools monitor network boundaries and API calls. They can't inspect what happens inside the reasoning loop. From the outside, file reads, code execution, and API calls look normal. LLM data security failures occur within this monitoring gap.
IBM's 2026 study found that one in four malicious breaches was AI-enabled. Those AI-enabled breaches cost $6 million on average, against a $4.99 million global average.
Key takeaways
- Traditional security can't see inside an agent's reasoning loop.
- Prompt injection, data disclosure, tool exfiltration, and excessive agency are the main vectors.
- MicroVMs isolate untrusted code, while containers share the host kernel.
- gVisor is stronger than containers and still has no hardware boundary.
- Isolation contains code, and you still need redaction, retrieval checks, and egress limits.
Why do traditional security models break down for agents?
Web applications process requests through well-defined paths. A user submits a form, the server validates inputs, queries a database, and returns a response. Security controls sit at each step.
Agents choose their own execution paths. They receive natural language instructions, decide which tools to call, and generate and run code.
The core issue is instruction ambiguity. The OWASP LLM01 risk is that LLMs treat instructions and data as the same text. Filtering doesn't fully fix this.
Once an agent has filesystem, API, and code access, a single prompt can chain them. The agent becomes the attack vector. It already has legitimate credentials and authorized tool access. The agent's legitimate access puts this attack beyond perimeter security's reach. The threat starts inside the trusted boundary.
What attack vectors matter most for code-executing agents?
Prompt injection is still the top risk. It holds LLM01 in the OWASP Top 10 2026, the current edition from the Open Worldwide Application Security Project (OWASP). But code-executing agents face several other categories of attack vectors in production.
Prompt injection bypasses intent, not authentication
Attackers embed commands in content the agent later processes. The agent then follows those commands through its normal workflow.
For example, the EchoLeak flaw (Common Vulnerabilities and Exposures ID CVE-2025-32711) let a crafted email pull data from Microsoft 365 Copilot with zero clicks. Aim Labs reported it in January 2025, and Microsoft fixed it server-side in May.
OWASP notes that prompt injection remains a risk with retrieval-augmented generation (RAG) and fine-tuning. Architectural isolation remains essential.
Remote code execution through generated code
Generated code is an execution surface, so an attacker can steer it toward dangerous operations or a weak sandbox. The Cloud Security Alliance describes a related path: MCP's STDIO transport can turn a connected server into remote code execution. The details vary by tool, and the pattern is the same.
Sensitive information disclosure through outputs and tool results
Sensitive Information Disclosure holds LLM02 in both the 2025 and 2026 OWASP lists. The OWASP LLM02 entry names personal data and proprietary algorithms as typical exposures. For code-executing agents, memorization creates a disclosure risk. The agent's own outputs, logs, and tool results create bigger leak paths.
While debugging a failed job, a coding agent reads an error log that contains a partial database credential. It then summarizes the log in a pull request comment visible to the whole org. The agent followed its instructions without any attacker involvement. Treat every agent output as a potential disclosure channel. Scan tool results and responses for secrets and personal data before they leave the sandbox. Log what the agent read alongside what it wrote.
Data exfiltration through legitimate tool access
When agents have API and filesystem access, attackers don't need credentials. They can manipulate the agent into exfiltrating data using its own authorized tools.
This vector is hard to spot because the traffic can look like normal API usage. In May 2025, Invariant Labs showed this against the GitHub Model Context Protocol (MCP) server. Per the Cloud Security Alliance (CSA)'s analysis, a malicious public issue hijacked an agent. The agent then pulled private repository data into a public pull request. CSA traced the root cause to a broadly scoped token plus a manipulable agent.
Excessive agency amplifies every other vulnerability
Broad permissions magnify impact. OWASP moved Excessive Agency from sixth in 2025 to LLM03 in 2026. An attacker can redirect autonomous capabilities toward unintended actions. Prompt hardening can't compensate for overbroad authority.
If an agent has wide read access and outbound network permissions, a prompt injection can redirect it. It can read configuration files and pull secrets from environment variables. Next, it can send that data to an external endpoint.
Each step uses legitimate permissions, so no privilege escalation is required and monitoring sees normal-looking calls. Least privilege, rate limits, and approvals for sensitive operations limit how far that chain can go.
How do the OWASP 2026 risks map to agent controls?
The 2026 edition reshuffled eight of ten categories, so security reviews built on the 2025 numbering now cite the wrong IDs. The table below pairs each 2026 risk with its rank in the 2025 edition. It also lists the control that matters most for code-executing agents.
| 2026 ID | Risk | 2025 rank | Primary control for code-executing agents |
|---|---|---|---|
| LLM01 | Prompt Injection | 1 | Run generated code in isolated sandboxes; treat all external content as untrusted |
| LLM02 | Sensitive Information Disclosure | 2 | Redact prompts, scan outputs, enforce access checks at retrieval |
| LLM03 | Excessive Agency | 6 | Least-privilege tool scopes and approval gates for sensitive actions |
| LLM04 | Supply Chain | 3 | Vet pre-trained models, datasets, and plugins before deployment |
| LLM05 | Data and Model Poisoning | 4 | Provenance checks on fine-tuning and embedding data |
| LLM06 | Unbounded Consumption | 10 | Per-agent budgets and rate limits |
| LLM07 | Misinformation | 9 | Verify outputs before the agent acts on them |
| LLM08 | Hidden Context Exposure (formerly System Prompt Leakage) | 7 | Keep secrets out of prompts and agent context |
| LLM09 | Vector and Embedding Weaknesses | 8 | Permission-aware vector stores with tenant separation |
| LLM10 | Improper Output Handling | 5 | Validate output before it reaches a shell, SQL query, or HTML page |
Update your threat model and audit evidence to the 2026 IDs.
How does isolation architecture define the security boundary?
Isolation technology determines whether a compromised agent stays contained. For agents executing untrusted or arbitrary code, microVM isolation provides the strongest boundary for multi-tenant workloads.
MicroVMs provide the strongest isolation for untrusted code
MicroVMs run complete operating systems with their own kernels. Guest-kernel exploits are normally contained within the guest. A vulnerability in the virtualization layer can still let an attacker reach the host.
Open-source microVMs like Firecracker power several production platforms. MicroVMs are the clearest fit for multi-tenant execution of untrusted code. In that setup, different customers' agents share infrastructure and each execution environment must be fully isolated.
When teams only run their own trusted software, containers remain the industry standard for multi-tenant workloads. The threat model depends on whether the code is trusted. Trusted code doesn't carry the same escape risk as arbitrary, AI-generated scripts.
Containers alone are insufficient for untrusted code
Containers share the host kernel. That shared kernel creates container escape paths. Kernel exploits and capability misuse are common themes.
Platforms that execute untrusted code use stronger boundaries like microVMs instead of bare containers. One kernel bug can expose every tenant on the host.
gVisor is improved, but not equivalent
gVisor intercepts system calls in user space. It reduces host kernel exposure and is stronger than standard containers. But it isn't the same as microVM separation because it doesn't provide a hardware-backed boundary.
In addition to isolation, agent workflows need execution controls. Block file writes outside the workspace. Protect configuration files from agent modification. Keep all execution tools inside one sandbox environment. Without those controls, even a strong isolation layer leaves the workspace itself open to agent edits.
How do you keep sensitive data out of prompts, logs, and model providers?
Isolation contains what generated code can touch. It doesn't control what the model sees, what the agent sends out, or what the provider keeps. Those decisions sit at the data layer:
- Redact before the prompt: Detect and mask or tokenize personally identifiable information (PII) before it reaches the model API. Keep the token mapping outside the model's reach, and re-insert real values only after the response returns.
- Keep secrets out of agent context: The 2025 OWASP document says to keep API keys, authentication keys, database names, and permission structures out of system prompts. Extend that to environment files, since agents with filesystem access can read them.
- Enforce access at retrieval time: The OWASP RAG Security Cheat Sheet recommends storing access metadata per chunk and checking it at both ingestion and retrieval. It also calls for tenant isolation and logging every retrieval with the requester's identity.
- Restrict outbound traffic: An allow-list of destination domains limits where a hijacked agent can send data. Egress controls and isolation address different threats, so plan for both.
Model providers are the other half of the data layer. Each one keeps API traffic under different defaults, and your agents inherit those terms.
| Provider | Default retention | Training on API data | Zero data retention (ZDR) path |
|---|---|---|---|
| OpenAI | Abuse-monitoring logs kept up to 30 days | Not used for training on /v1/chat/completions and /v1/responses | Requires prior approval; /v1/conversations and /v1/agents are not ZDR eligible |
| Anthropic | Inputs and outputs deleted within 30 days, with exceptions for agreements, policy enforcement, and legal requirements | No commercial training absent feedback or permission | ZDR agreements cover eligible APIs, including Claude Code via API; Covered Models still retain 30 days |
| Google (Gemini Developer API) | Paid Services log prompts briefly to detect prohibited use | See Google's API terms | Approved ZDR clears content and identifiable metadata before logging |
| Azure OpenAI | Not stored for automated review; human-review store separated per resource | Not used to train models | Microsoft's Learn Q&A answers describe ZDR as modified abuse monitoring that requires approval |
Abuse-monitoring logs can hold a copy of prompts and responses outside your sandbox. Eligible customers can apply to have that content excluded. Before production:
- List each model endpoint your agents call.
- Record its retention terms.
- Request ZDR where your contract qualifies.
What do breach-cost metrics imply for security investment?
IBM's 2026 report includes AI-specific breach baselines. IBM's analysis reports that 21% of breached organizations had an incident involving an AI model or application. That's up from 13% in 2025. Organizations with those incidents averaged $5.33 million per breach, compared with $4.70 million.
IBM X-Force names model inversion (6.07million)andpromptinjection(5.89 million) as the costliest AI incident types. Prompt injection is one of the vectors above. Model inversion targets training data rather than live tool access. Among organizations that reported an AI-related breach, 92% lacked proper AI access controls. That makes access control one of the most direct gaps to close.
Which compliance frameworks apply to agent workloads?
Several data governance frameworks can apply at once. Common ones are SOC 2, GDPR, HIPAA, the NIST AI RMF, and ISO standards. ISO/IEC 42001:2023 covers AI management systems. The EU AI Act can add timelines and risk classification.
Across frameworks, the technical controls converge. They include encryption, access control, audit logging, isolated execution, documentation, and human oversight.
EU deadlines have shifted. Multi-quarter work is common when stacking requirements. The AI Omnibus reset the EU AI Act high-risk dates.
| Event or obligation | Effective or application date |
|---|---|
| AI Omnibus took effect | 27 July 2026 |
| Stand-alone Annex III high-risk obligations | 2 December 2027 |
| High-risk AI embedded in products | 2 August 2028 |
| Most other transparency obligations | Already apply as of 2 August 2026 |
Check which obligations touch your product now.
For startups, compliance affects revenue directly. Many enterprise buyers require SOC 2 early. HIPAA is mandatory for healthcare data held by covered entities and business associates. GDPR applies to personal-data processing by an EU establishment. It also applies outside the EU when you offer goods or services to people there, or monitor their behavior. Missing any of these artifacts can stall deals.
How do you strengthen LLM data security with production isolation?
Make LLM data security, and AI agent security more broadly, part of your architecture decisions before production. For coding agents and PR review agents that execute untrusted code, start with microVM isolation. Then add the data-layer controls covered above.
For teams that would rather not operate Firecracker themselves, Blaxel runs each sandbox in its own Firecracker microVM. Filesystem, processes, and network stay separate per execution. Sandboxes resume from standby in under 25ms, and they return to standby after 15 seconds of network inactivity. Blaxel keeps sandboxes in standby with no time limit, while higher quota tiers support unlimited persistence. Standby has no compute charge, and only snapshot and volume storage is billed.
For the data layer, outbound domain filtering limits where a hijacked agent can send data. Proxy secrets injection is in public preview and is not recommended for production. It adds credentials to outbound requests so agent code never sees raw secrets. Dedicated egress gateways, in private preview, give sandboxes static outbound IPs for allow-listing. AAgent Drive, in private preview, gives agents shared storage, and during the preview it runs only in us-was-1. The drive and the sandbox both have to be in that region. Built-in OpenTelemetry tracing records agent executions for audits. Blaxel maintains SOC 2 Type II, HIPAA, and ISO 27001, with a Business Associate Agreement available for HIPAA workloads.
Review the Blaxel security and compliance details against your requirements. If Blaxel fits your coding-agent execution requirements, book a demo to review your agent's threat model with Blaxel's founding team.
Deploy agents with production-grade isolation
For coding agents executing untrusted code: microVM sandboxes, sub-25ms resume, and built-in observability. SOC 2 Type II certified, with a Business Associate Agreement available for HIPAA workloads. Zero compute cost during standby.
Book a demo or start free with $200 in credits.
FAQs about LLM data security
What is the biggest security risk when LLMs execute code?
Prompt injection is the top risk and holds LLM01 in OWASP's 2026 edition. LLMs can't separate instructions from data, so attackers embed malicious commands in content the agent processes.
When the agent can execute code, injection can become arbitrary execution. Prompt injection remains possible with RAG and fine-tuning. Defense needs isolation, least privilege, and output validation.
How do microVMs differ from containers for AI agent security?
Containers share the host OS kernel. That creates escape paths through kernel exploits and capability abuse. MicroVMs run complete operating systems with separate kernels, so a guest-kernel exploit stays in the guest. A bug in the virtualization layer can still reach the host.
Open-source microVMs like Firecracker power several production platforms. For agents running untrusted, AI-generated code, that hardware-enforced boundary matters.
What compliance frameworks apply to AI agents processing sensitive data?
Common frameworks include SOC 2, GDPR, HIPAA, NIST AI RMF, and ISO standards. The EU AI Act can also apply. All require strong access controls, auditability, and protections for processing environments.
After the 2026 AI Omnibus, stand-alone high-risk EU AI Act obligations come due on 2 December 2027. Product-embedded high-risk systems follow on 2 August 2028.
Do LLM providers keep the data your agents send?
Usually, for a limited period. OpenAI keeps abuse-monitoring logs for up to 30 days by default. Anthropic deletes API inputs and outputs within 30 days, with exceptions. Both offer zero data retention for eligible use cases through approval or agreement. The provider table above lists the details per vendor. Check each endpoint your agents call, because some, such as OpenAI's /v1/agents, aren't ZDR eligible.
How much does an AI-related data breach cost?
Costs vary by organization and breach type. IBM's 2026 data puts both AI-enabled breaches and breaches involving an AI model or application above the global average.
Prompt injection and model inversion were the costliest AI incident types in IBM's data. Those costs strengthen the case for isolation and access-control spending.
Related articles

Guides
How network sovereignty keeps your AI agents' traffic, data, and execution under your control
Learn how network sovereignty for AI agents differs from data residency, which regulations apply, and which egress, region, and credential controls to deploy.
14 min read

Guides
Blaxel + Claude: secure code execution for AI agents
Run Claude Managed Agents with self-hosted sandboxes on Blaxel. Control data residency, network egress, and state persistence.
15 min read

Guides
How to run Claude tool use with Blaxel sandboxes
Compare three Claude integration paths on Blaxel: Claude Code, Agent SDK, and Claude Managed Agents. Each runs tool calls inside isolated microVM sandboxes.
13 min read