Security

    LangChain and AutoGPT Have Zero Memory-Integrity Safety. One Poisoned Write Breaks 88.9% of Decisions.

    Three major agent frameworks—LangChain, AutoGPT, and OpenAI Agents SDK—ship with zero memory-integrity safeguards. Here's what that costs you.

    ← All posts
    18 min readBy The Mesh API Team

    Memory poisoning attack: an attacker inserts malicious data into an agent's persistent memory, causing all future decisions to be corrupted.A malicious actor writes a poisoned entry into an agent memory store while downstream agents read from it, their decision paths lit in red.

    TL;DR

    • 🔴 LangChain, AutoGPT, and the OpenAI Agents SDK have zero native memory-integrity safeguards — confirmed by an audit of all three frameworks against six formal safety principles (The Containment Gap, arXiv:2606.12797, June 2026)
    • 🔴 A single poisoned memory write causes 88.9% wrongful denials in a realistic LangChain benefits-eligibility agent, persistent across five backend models including GPT-4o, Claude Haiku 4.5, and Claude Sonnet 4.6
    • 🔴 Independent research shows >90% attack success rate on GPT, Claude, and Gemini agents across both LangChain and LlamaIndex (Memory Control Flow Attacks, Koala Science, 2026)
    • 💡 Standard monitoring won't catch it: aggregate accuracy stays normal while a targeted subgroup is systematically harmed — the attack is designed to be invisible
    • 💡 Defenses are cheap: a memory-integrity validator and policy gate eliminate both attack vectors with <0.2 ms overhead per call — less than 0.1% of a typical LLM round-trip
    • 🛠 If your agent makes high-stakes decisions (approvals, access control, financial), audit your memory layer before you ship to production

    Three mainstream agentic frameworks — LangChain, AutoGPT, and the OpenAI Agents SDK — ship with no built-in memory-integrity protections. Not weak ones. None.

    This isn't a theoretical observation. A June 2026 paper audited all three frameworks against six formal safety principles and found zero compliance across the board (arXiv, "The Containment Gap: How Deployed Agentic AI Frameworks Fail Safety Norms," 2026). The researchers then ran a concrete test: a LangChain-based benefits-eligibility agent, realistic policy criteria, five backend models. They wrote one poisoned memory entry. The result was an 88.9% wrongful denial rate for targeted applicants — persistent across every model and every test run.

    That number should alarm you. Not because the vulnerability is novel, but because of what it means at scale: an attacker who can write one lie into your agent's memory can silently corrupt every decision that agent makes, indefinitely, without triggering a single alert.


    The Containment Gap: What Was Actually Tested

    The Containment Gap paper (arXiv:2606.12797) is a systematic audit, not a CVE disclosure. Its authors proposed six formal safety principles that a safe agentic framework should implement natively, then checked whether LangChain, AutoGPT, and the OpenAI Agents SDK comply with any of them:

    • P1 — Isolation: Agents can't read each other's memory
    • P2 — Immutability: Memory writes are logged and can't be silently modified
    • P3 — Memory Integrity: Memory entries are validated before the agent acts on them
    • P4 — Policy Gates: Rules govern who can write to memory and under what conditions
    • P5 — Provenance Tracking: Memory entries carry source and timestamp metadata
    • P6 — Containment: Agent memory access can be scoped (read-only, time-bounded, role-based)

    The audit's conclusion: "We do not observe native compliance across any of the six principles." The paper states directly: "Memory integrity, a defense against one of the most prevalent vulnerability classes, is not observed in any of the three evaluated frameworks."

    Then they proved why it matters. They built a government benefits-eligibility agent on LangChain, tasked it with approving or denying applications based on income, household size, and location. They tested it against five backend models: GPT-4o, Claude Haiku 4.5, Claude Sonnet 4.6, GPT-4o-mini, and Qwen-2.5 3B.

    The attack was simple. One poisoned memory write — a false entry claiming targeted applicants lived in a restricted zone. The result: 88.9% of eligible targeted applicants were wrongfully denied, persistently, across all five backends and all tested seeds.

    Under a more complex five-factor policy, the same attack was even stealthier: it preserved overall approval accuracy while increasing targeted wrongful denials by 3.5× (arXiv, "The Containment Gap," 2026). Nothing in aggregate metrics would flag it.


    Why Framework Defaults Make This Easy

    Memory poisoning doesn't require fooling the model. It just requires writing down a lie in a place the model trusts.

    Inside the agent loop, memory is indistinguishable from ground truth. When an agent starts a new session, it loads its persistent memory and treats everything there as established fact. There's no middleware asking "who wrote this?" or "has this been tampered with?" or "is this entry consistent with the domain model?" It's all equally trusted.

    The attack surface is broad:

    • A compromised tool output — a web scraper or API call that writes back to memory can inject false state
    • An injected document — in a RAG system, a user who uploads a file can plant entries that get written to persistent memory
    • Direct database access — lateral movement in a production environment that lets an attacker write directly to the memory store

    Three-panel flow diagram showing clean memory being poisoned by an attacker, followed by an agent reading the poisoned entry and returning a wrong decision.The attack path: an attacker gains write access to agent memory, inserts a false entry, and all subsequent agent decisions are corrupted.

    This is also structurally different from prompt injection. A prompt injection attack targets a single session — the user might notice the model behaving strangely. Memory poisoning is stateful: it changes the agent's durable knowledge base. Every future session inherits the corruption, and there's nothing in the output to suggest anything is wrong.

    LangChain's memory module, AutoGPT's persistent state, and the OpenAI Agents SDK's thread memory are all designed to give agents continuity across sessions. That continuity is a feature. The problem is that none of these frameworks treats memory as an untrusted input that needs validation before it shapes decisions.


    The Real Cost: 88.9% Corruption in One Realistic Test

    The 88.9% figure deserves unpacking. It's not a success rate for the attack (breaking the auth layer, exfiltrating data). It's a decision outcome rate for real end-users.

    In the Containment Gap experiment, eligible applicants — people who met every policy criterion — were denied benefits at an 88.9% rate because the agent's memory had been poisoned about them. The agent wasn't confused or slow. It was operating perfectly normally on corrupted beliefs.

    Wrongful Denial Rate Under Memory Poisoning (by Backend) 100% 80% 60% 40% 20% 0% ~20% normal 88.9% GPT-4o 88.9% Claude Haiku 4.5 88.9% Claude Sonnet 4.6 88.9% GPT-4o-mini 88.9% Qwen-2.5 3B Wrongful denial rate for targeted applicants after single memory-poisoning write — all five backends Source: The Containment Gap, arXiv:2606.12797 (June 2026)

    What makes the stealthy variant worse: under a complex five-factor policy, the attack preserved aggregate approval accuracy while increasing targeted denials by 3.5× (arXiv, "The Containment Gap," 2026). Your dashboard would show a normal approval rate. Your error logs would be clean. The only signal is that a specific subgroup is being systematically harmed — and standard monitoring rarely looks at subgroup outcomes.

    If your agent governs access control, financial approvals, or any high-stakes eligibility decision, this attack pattern represents a direct business and legal risk, not a theoretical one.


    Broader Evidence: This Isn't a LangChain Problem. It's a Category Problem.

    Independent research from Koala Science on Memory Control Flow Attacks (MCFA) tested a different attack type — adversarial entries that redirect agent tool calls and workflow decisions — and found >90% attack success rate across GPT-5 mini, Claude Sonnet 4.5, and Gemini 2.5 Flash on both LangChain and LlamaIndex (Koala Science, "Memory Control Flow Attacks on LLM Agents," 2026).

    The paper's framing: "Adversarially crafted persistent memory entries can redirect LLM agent tool-call traces with >90% ASR across GPT, Claude, and Gemini on both LangChain and LlamaIndex."

    Two independent research groups. Two different attack designs. Consistent conclusion: unguarded memory in agent frameworks is an open control channel, regardless of which LLM backend you're using.

    Three framework icons — LangChain, AutoGPT, OpenAI Agents SDK — each marked with a large red failure indicator showing zero compliance with memory safety principles.All three major agent frameworks fail basic memory-integrity checks — this is a systemic issue, not a single vendor's bug.

    The CVE record reinforces the picture. Orca Security disclosed CVE-2025-68664 (CVSS 9.3) in LangChain's core library — a deserialization flaw that allows attackers to steal sensitive data via prompt injection (Orca Security, "CVE-2025-68664 LangChain Flaw," 2025). A follow-on analysis identified CVE-2025-68665 (CVSS 8.6) in LangChain Core for unsafe serialization boundaries — the root cause being a trust boundary violation in object reconstruction that lets crafted payloads bypass type enforcement (LinkedIn/Mahesh Ramichetty, "Critical LangChain Core Vulnerability," 2025). Check Point Research found a critical vulnerability chain in LangGraph with three CVEs: CVE-2025-67644 (SQLite injection), CVE-2026-28277 (msgpack RCE), and CVE-2026-27022 (Redis injection) — all since patched (Check Point Research, "When Your AI Agent's Memory Becomes a Security Liability," 2026).

    The ecosystem is enormous. CSA Labs reports LangChain and LangGraph were collectively downloaded more than 84 million times in a single reporting week (Cloud Security Alliance, "LangChain/LangGraph: Critical Flaws in the AI Dev Stack," 2026). LangGraph alone has approximately 46.5 million monthly downloads (Check Point Research, 2026). One analysis estimated 278,000 AI projects at risk from the LangChain CVE cluster (AIforAutomation.io, "LangChain 3 CVEs: 278K AI Projects at Risk," 2026).


    What's Actually Missing: Six Principles, Zero Compliance

    The Containment Gap researchers weren't looking for edge cases. They proposed six principles that any safety-conscious framework should implement and found LangChain, AutoGPT, and the OpenAI Agents SDK fail all six:

    Framework Safety Compliance Matrix — The Containment Gap Framework Safety Compliance Matrix LangChain AutoGPT OpenAI Agents SDK P1: Isolation P2: Immutability P3: Memory Integrity P4: Policy Gates P5: Provenance P6: Containment ✗ ✗ ✗ ✗ ✗ ✗ ✗ ✗ ✗ ✗ ✗ ✗ ✗ ✗ ✗ ✗ ✗ ✗ Source: The Containment Gap, arXiv:2606.12797 (June 2026)

    Each failure mode is distinct:

    P1 — Isolation is absent in multi-agent systems like CrewAI or AutoGPT, where agents share memory pools. Agent A can read and potentially corrupt Agent B's state.

    P2 — Immutability means memory writes should be append-only or logged in a way that detects tampering. Current frameworks store memory in standard databases where rows can be overwritten silently.

    P3 — Memory Integrity is the critical one. There's no middleware that asks "is this entry authorized?" or "is it consistent with the domain model?" The model sees memory entries as part of its context and reasons from them as fact.

    P4 — Policy Gates would restrict who can write to memory. In a benefits agent, should raw user input ever write directly to long-term memory? Almost certainly not — but nothing prevents it.

    P5 — Provenance Tracking means entries carry metadata: who wrote them, when, via which tool. None of the three frameworks do this by default.

    P6 — Containment would allow scoping memory access — read-only for certain agents, time-bounded, or role-restricted. Also absent.

    The result is that all three frameworks treat memory as a free-form key-value store with full trust and no guards.


    Proof of Concept: Lightweight Defenses That Actually Work

    Here's the part security posts usually skip: the fix isn't hard.

    The Containment Gap paper proposes two mechanisms that together eliminate both demonstrated attack vectors with sub-millisecond overhead — specifically, less than 0.2 ms per call (arXiv, "The Containment Gap," 2026).

    Memory-Integrity Validator: Sits between memory and the agent. On each read, it checks that entries conform to expected schema, haven't been corrupted, and are consistent with the domain model. If a benefits agent expects Location: {city, state} and memory contains Location: restricted_zone_7, the validator rejects or flags it before the agent acts. Hash-based consistency checks make this fast.

    Policy Gate: Controls writes to memory. Before a tool output or user-submitted data gets written to persistent memory, a policy check runs: "Is this source authorized to write this entry type?" For high-stakes agents, writes can require explicit approval or be restricted to verified system sources only.

    Before-and-after architecture diagram: left shows agent reading directly from unprotected memory; right shows two protective middleware layers — Memory Integrity Validator and Policy Gate — between memory and agent.Adding a memory-integrity validator and policy gate eliminates memory-poisoning attacks with negligible latency overhead.

    Why the overhead number matters: a typical LLM inference call costs 200–500 ms. Adding 0.2 ms for memory safety is a 0.04–0.1% overhead. For practical purposes, it's free.

    Neither mechanism requires swapping frameworks. Both can be implemented as middleware at the memory layer — in LangChain, as a custom memory class that wraps an existing store with validation logic. You keep the same framework, the same agent design, the same models. You add one abstraction layer.

    This is the same pattern web frameworks taught us about CSRF and SQL injection. The framework doesn't prevent SQL injection by default — you add parameterized queries. LangChain doesn't validate memory writes by default — you add a validator. The architectural principle is identical.

    Teams can also find inspiration in community-built tools like OWASP Agent Memory Guard and the MemGuard prototype, which implement similar protective layers on top of existing LangChain memory infrastructure. The Containment Gap paper provides a reference implementation worth studying directly.

    If adding a custom memory class to your stack isn't feasible, a pragmatic fallback is read-only memory for critical decision paths: the agent can read memory but only verified system writes can modify it. This doesn't fully implement P3 through P6, but it eliminates the most dangerous attack vector — untrusted writes that persist across sessions.

    You can test multiple memory-safety configurations side by side using Mesh API's compare endpoint — useful for verifying that your validator behaves consistently across model backends before shipping to production.


    Why This Matters Right Now

    Agent frameworks aren't research tools anymore. Companies are shipping LangChain agents into production for loan approvals, fraud detection, benefits processing, and customer escalation triage. AutoGPT-based systems are running automated procurement and access-grant workflows.

    The attacker motivation is high and the barrier is low. Poisoning an agent's memory doesn't require a zero-day exploit or a sophisticated prompt that fools the model. It requires write access to a memory store — achievable via a compromised integration, an injected document, or lateral movement in a production environment. Once written, the corruption is durable, invisible to standard monitoring, and affects every future session.

    There's also a regulatory dimension that will only grow. If your agent makes decisions subject to audit — financial lending, healthcare authorization, hiring, government benefits — "we couldn't tell if the agent's memory had been tampered with" is not an acceptable answer in a compliance conversation. You can't certify a decision made by an agent operating on potentially corrupted beliefs.

    The detection gap is structural: teams watch aggregate metrics. Approval rates, error rates, latency. A memory-poisoning attack that targets a specific subgroup while keeping aggregate metrics stable will not appear in your dashboards. You're essentially flying blind unless you implement integrity checks or explicit subgroup monitoring.

    The good news is that the fix is available, cheap, and well-specified. The question is whether teams implement memory safety before they ship to production, or after an incident forces the conversation.


    FAQ

    Is this only a problem for LangChain, or does it affect other frameworks?

    It's a category-level problem. The Containment Gap audit tested LangChain, AutoGPT, and the OpenAI Agents SDK — all three failed all six principles. Independent MCFA research found >90% attack success on LangChain and LlamaIndex. Any agent framework that treats persistent memory as fully trusted will have this vulnerability. The specific attack vectors vary; the underlying absence of memory integrity validation does not.

    Can standard prompt injection defenses protect against memory poisoning?

    No. Prompt injection defenses work on the current input — they filter what enters the model's context in a single session. Memory poisoning is stateful: the malicious entry is already inside the agent's persistent knowledge base before the session starts. Standard defenses don't inspect memory on read, so they offer no protection. You need integrity validation at the memory layer itself.

    What's the difference between this and a SQL injection attack?

    Structurally similar. Both allow attackers to insert untrusted data into a system's state without validation. Memory poisoning is "state injection" into an agent's knowledge base, just as SQL injection is data injection into a database. The defense is also parallel: validate before trusting, enforce least privilege on writes, log all state changes. The frameworks haven't caught up to this lesson yet.

    If I'm using LangChain, does this mean I can't deploy agents in production?

    No. It means you need to add defenses before deploying to high-stakes contexts. The Containment Gap paper shows that memory validators and policy gates eliminate the demonstrated attacks with <0.2 ms overhead. You can deploy LangChain safely — the same way you deploy Express.js safely by adding authentication middleware. The framework doesn't include it by default; you add it as a layer.

    How would an attacker actually poison our agent's memory in practice?

    Three main vectors. First, compromised tool output: a tool your agent calls — a web scraper, an API client, a data fetcher — returns a malicious value that gets written to memory as if it were legitimate state. Second, injected documents: in a RAG setup, a user uploads a file containing crafted content that lands in the vector store and persists as memory. Third, direct database access: an attacker with lateral movement in your infrastructure writes directly to the underlying memory store. The first two are available to any user of your system; the third requires deeper access but is the hardest to detect after the fact.