AI agent memory security is the practice of protecting the long-term and working memory systems that AI agents use to remember facts, preferences, prior tasks, tool results, retrieved documents and execution history. As agents become stateful across sessions, memory stops being a convenience layer and becomes part of the security boundary.
A poisoned memory can survive long after the original malicious input disappears. It may be retrieved hours, days or weeks later and quietly influence planning, tool use, identity decisions or access to sensitive data. That makes memory attacks fundamentally different from one-shot prompt injection: the malicious influence can become persistent.
This guide explains memory poisoning, memory injection, sleeper attacks, memory extraction, provenance, write-time validation, retrieval-time filtering, zero-trust memory architecture, repair and deletion, and the controls needed to operate long-term agent memory safely in production.
What Is AI Agent Memory Security?
AI agent memory security protects the integrity, confidentiality and authority of information that an agent stores and later retrieves. It applies to several forms of state:
- conversation history;
- user preference memory;
- episodic memory from previous runs;
- semantic memory and learned facts;
- vector database entries;
- tool outputs saved for reuse;
- summaries generated by the agent;
- retrieval caches;
- task plans and execution traces;
- shared memory used by multiple agents.
The security problem begins when a memory item is treated as trusted simply because it was stored previously. Past data may have originated from an untrusted webpage, a malicious email, another user, a compromised tool, or an earlier prompt-injection attempt.
Memory security therefore needs to answer four questions for every stored item: where did this memory come from, who was allowed to write it, how much authority should it have, and is it still safe to use now?
Why Persistent Memory Creates a New Attack Surface
A stateless model forgets the malicious interaction when the session ends. A stateful agent may preserve parts of that interaction and retrieve them later. This persistence changes the threat model.
Microsoft’s security guidance describes AI memory/context poisoning as corruption of long-lived memory channels such as persistent context stores, preference memories, vector databases and conversation histories. The danger is durability: poisoned content can influence future reasoning and actions after the original attack is no longer visible.
Persistent memory also increases privacy risk. If an agent stores sensitive details and retrieval controls are weak, an attacker may try to extract information belonging to another user or previous session.
In production, memory should therefore be treated more like a security-sensitive database than a harmless chat transcript.
Memory Poisoning vs Prompt Injection
Prompt injection attempts to influence the agent during the current interaction. Memory poisoning attempts to make that influence persist by causing malicious or false information to be written into long-term memory.
The two attacks can work together. An attacker may use prompt injection to persuade an agent to save a false fact, malicious instruction or altered identity mapping. Once stored, later sessions may retrieve the poisoned record as if it were normal historical context.
This creates a dangerous security transition:
- untrusted content enters the agent;
- the model interprets it;
- a memory system saves part of the interaction;
- the original malicious wording disappears;
- the stored summary looks legitimate;
- a future task retrieves it;
- the agent acts on the poisoned memory.
That delayed behavior is why memory security cannot rely only on input filtering.
What Is a Memory Injection Attack?
A memory injection attack causes an agent to store attacker-controlled information in a form that later affects another task or user.
The best-known academic example is MINJA (Memory INJection Attack). The attack was presented at NeurIPS 2025 and demonstrated that attackers can poison an agent’s memory through query-only interaction without directly modifying the memory database.
MINJA uses bridging steps and progressive shortening. The attacker gradually teaches the agent a malicious relationship or reasoning pattern. Over repeated interactions, the explicit suspicious instruction can disappear while the harmful semantic association remains in memory.
This matters because simple keyword filters may only inspect the final stored text. If the dangerous meaning has been compressed into an apparently normal summary, the memory may survive those checks.
What Is Sleeper Memory Poisoning?
Sleeper memory poisoning is a delayed attack in which malicious information is stored now but activated only when a matching future condition appears.
A 2026 study titled Hidden in Memory: Sleeper Memory Poisoning in LLM Agents evaluated attacks in which malicious content from documents, webpages or repositories causes assistants to save fabricated user memories. The researchers reported that poisoned memories could be written at very high rates in tested systems and, when successfully retrieved, could drive attacker-intended agent actions in a substantial share of evaluations.
The critical feature is latency. The attack may remain dormant across several unrelated conversations. That breaks the normal assumption that the suspicious input and the harmful action occur close together in time.
GhostWriter and Tool-Using Personal Agents
A July 2026 paper, When Agents Remember Too Much, introduced GhostWriter, a memory-poisoning attack aimed at tool-using personal agents.
The attack has two stages:
- Injection: malicious content is introduced through an interaction or external source and saved to memory.
- Activation: a later task retrieves the poisoned memory and uses it during planning or tool execution.
The researchers reported approximately 98% injection and around 60% average activation in their evaluated agent setups. They proposed a defense called AM-Sentry that combines a memory-saving policy with a retrieval screen.
The broader lesson is important: protecting only memory writes is not enough. A secure architecture needs controls at both write time and retrieval time.
What Is a Memory Extraction Attack?
Memory security is not only about integrity. It is also about confidentiality.
MEXTRA (Memory EXTRaction Attack) was introduced in research published at ACL 2025. It showed that a black-box attacker could design prompts that encourage an agent to reveal information stored from prior user-agent interactions.
The privacy risk grows when memory systems:
- mix data from multiple users;
- lack tenant-level namespaces;
- store raw conversations unnecessarily;
- return memory records without authorization checks;
- allow broad semantic search over sensitive history;
- treat model-generated requests as inherently authorized.
Memory retrieval should therefore be authorized just like an API request. Relevance is not permission.
Memory Poisoning in RAG and Vector Databases
Many agent memory systems are implemented with vector databases or retrieval-augmented generation. This makes retrieval quality part of the security boundary.
A poisoned item that receives a high similarity score may be repeatedly retrieved for related queries. If the memory system lacks provenance or trust metadata, the model may not distinguish between a verified system fact and an attacker-controlled note.
Research on retrieval-augmented LLM agents in 2026 has shown that deceptive semantic reasoning can be used to create stealthy poisoned memories that remain effective across models and retrievers.
For the architecture differences between memory and RAG, see Vynula’s AI Agent Memory vs RAG vs Vector Databases guide.
Why Summaries Can Launder Untrusted Memory
Many production memory systems do not store raw conversations. They ask the model to summarize a session and save the summary. That can reduce storage cost, but it does not automatically make the memory safe.
A 2026 preprint on securing LLM-agent long-term memory argues that malicious origin can be laundered through summarization, trusted-tool echoes or manufactured corroboration. The resulting memory may look clean even though its authority ultimately came from an untrusted source.
This leads to a crucial rule: trust should not be derived only from the text of a memory item. Systems need non-malleable provenance that preserves where the information came from, even after summarization or transformation.
Use Provenance for Every Memory Write
Every production memory record should carry provenance metadata. At minimum, useful fields include:
- memory ID;
- user or tenant ID;
- agent ID;
- run ID;
- source type;
- source URL or tool;
- original trust classification;
- timestamp;
- writer identity;
- transformation history;
- content hash;
- retention policy;
- allowed retrieval scopes;
- review or approval status.
Provenance should survive transformations. If an untrusted webpage is summarized by the agent, the summary should still be marked as derived from an untrusted webpage.
Build a Memory WriteGuard
A WriteGuard is a policy layer placed before long-term memory persistence. It decides whether a candidate memory may be stored and with which authority.
A WriteGuard can evaluate:
- whether the current user is allowed to create persistent memory;
- whether the source is trusted or untrusted;
- whether the content contains instructions rather than facts;
- whether the memory contradicts existing verified records;
- whether the item changes identity, permissions or security configuration;
- whether the content contains secrets or sensitive personal data;
- whether the memory should expire quickly;
- whether human approval is required.
The safest default is not “store everything.” Memory should be selective.
Separate Facts, Preferences, Instructions and Authority
One common design mistake is to store all memory in one undifferentiated vector collection.
Production systems should separate memory by type. A user preference such as “prefer concise summaries” should not have the same authority as a security instruction, account owner record or tool permission.
Useful categories include:
- preferences: style and workflow choices;
- facts: user- or organization-specific information;
- episodic records: what happened during a prior run;
- tool observations: results returned by external systems;
- instructions: explicit approved operational rules;
- security state: identities, permissions and policy decisions.
High-authority memory should come from stronger sources than ordinary conversation.
Use Retrieval-Time Memory Screening
Write-time validation cannot catch every attack. Memories may become unsafe because policies change, a source is later compromised, or an attack is recognized only after several related records appear.
A retrieval gate should therefore re-evaluate candidate memories before they enter the model context.
Retrieval checks may include:
- tenant authorization;
- source trust;
- memory age;
- current policy;
- revocation status;
- semantic anomaly score;
- contradiction checks;
- known attack signatures;
- sensitivity classification;
- required approval level.
The retrieval layer can remove, redact, quarantine or downgrade suspicious memories instead of passing them directly to the model.
Zero-Trust Memory Architecture
A zero-trust memory design assumes that no memory item is trusted merely because it already exists in the database.
The 2026 Cognitive Autonomous Memory Security (CAMS) research proposes a multi-layer memory-defense architecture that combines semantic intent analysis, temporal monitoring, graph-based attack reconstruction, zero-trust write controls, provenance and periodic long-term-memory scanning.
In its experimental evaluation, CAMS reported 92.3% end-to-end prevention across tested MINJA and MEXTRA attack sequences, compared with weaker keyword-filter and LLM-only baselines. The evaluation used a clinical-agent testbed and synthetic attack corpus, so the result should be treated as evidence for the architecture rather than a universal production guarantee.
Monitor Memory Drift Over Time
Memory poisoning may be gradual. One update may appear harmless, while a series of small changes moves a memory toward a malicious meaning.
Temporal monitoring can track:
- embedding drift;
- unexpected changes to named entities;
- identity remapping;
- privilege-related wording;
- rapid updates from one source;
- contradiction clusters;
- cross-user relationships;
- changes in retrieval frequency.
This is useful against staged attacks such as progressive shortening, where the malicious signal is spread across multiple interactions rather than one obvious payload.
Quarantine Suspicious Memories Instead of Deleting Immediately
Automatic deletion can destroy forensic evidence. A safer incident workflow often moves suspicious memory into quarantine.
Quarantine can:
- remove the item from normal retrieval;
- preserve the original content and provenance;
- record which runs retrieved it;
- identify related memories;
- support investigation and recovery;
- allow later restoration if the alert was a false positive.
For high-risk systems, teams should be able to trace every downstream action influenced by the poisoned item.
Memory Repair and Selective Forgetting
Once poisoning is discovered, simply deleting one record may not be enough. The agent may have created summaries, plans or derived memories based on the poisoned item.
A repair workflow should identify descendants and dependent memories. Useful mechanisms include:
- provenance graphs;
- version history;
- dependency tracking;
- retroactive re-evaluation;
- rebuilding summaries from trusted sources;
- selective forgetting;
- re-indexing the vector store;
- revoking cached outputs.
This is similar to data lineage in analytics systems: if an upstream record is corrupted, derived outputs may also need remediation.
Protect Cross-User and Multi-Tenant Memory
Multi-tenant systems should not depend on semantic relevance alone to separate users. A vector database may return the most similar record even if it belongs to another tenant unless hard filters are applied.
Production memory systems should enforce tenant boundaries before similarity search results reach the model.
Controls can include:
- separate namespaces;
- tenant IDs enforced by the database layer;
- row-level security;
- per-user encryption keys;
- retrieval authorization;
- strict filtering before vector ranking;
- cross-tenant leakage tests.
This directly reduces the risk demonstrated by memory-extraction research.
Do Not Store Secrets in Model-Visible Memory
Passwords, API keys, private tokens and long-lived credentials should not be saved in ordinary agent memory.
Secrets belong in a credential manager or broker. The agent should receive narrowly scoped capabilities at execution time instead of retrieving raw secrets from vector memory.
Vynula’s AI Agent Identity and Authentication Explained covers short-lived credentials, workload identity and authorization in more detail.
Memory Security and Agent Governance
Memory security also needs governance. Organizations should define which agents are allowed to remember information, what categories may be retained, how long memory persists, who can inspect it and how users can request deletion.
Important governance questions include:
- Which memory types are enabled?
- Is memory opt-in or automatic?
- What is the retention period?
- Which data classifications are prohibited?
- Who can approve high-authority memory?
- How are memory policy changes versioned?
- How are incidents investigated?
- Can users inspect and delete stored memory?
Persistent memory should never become invisible organizational state.
Memory Security and Context Engineering
Memory is one input to the agent’s broader context. Context engineering determines how instructions, retrieved documents, tool results, conversation state and long-term memory are assembled before the model reasons.
Security should preserve trust boundaries inside that context. Verified policy should not be blended with untrusted retrieved text in a way that makes their authority indistinguishable.
See Vynula’s Context Engineering for AI Agents guide for the broader architecture.
Production AI Agent Memory Security Checklist
- Do not automatically store every conversation.
- Classify memories by type and authority.
- Bind immutable provenance to every memory write.
- Keep tenant boundaries outside the model.
- Validate candidate memories before persistence.
- Use separate controls for facts, preferences and instructions.
- Prevent ordinary conversation from rewriting security state.
- Screen memories again at retrieval time.
- Preserve source trust across summarization.
- Use short retention for low-value memory.
- Never store raw secrets in model-visible memory.
- Monitor semantic drift and suspicious update chains.
- Quarantine suspicious memories.
- Track downstream memories derived from poisoned records.
- Support selective forgetting and repair.
- Re-scan historical memory when new attack patterns are discovered.
- Test memory extraction across users and tenants.
- Log memory writes, retrievals, edits and deletions.
- Require stronger approval for high-authority memory.
- Include memory compromise in incident-response plans.
Common Memory Security Mistakes
Assuming old information is trusted
Age is not evidence of legitimacy. Old memory may simply be old poisoned memory.
Using one vector store for every memory type
Preferences, tool outputs, security policy and user facts should not share equal authority.
Filtering only at input time
Sleeper attacks can activate long after the original input. Retrieval-time controls are essential.
Trusting model-generated summaries
Summarization can hide malicious origin. Provenance must survive transformation.
Using similarity as authorization
A relevant memory is not necessarily a memory the current user is permitted to access.
Deleting suspicious memory without tracing dependencies
Derived summaries and downstream records may remain poisoned.
Storing secrets in memory
Long-term memory is not a credential vault.
How Memory Security Fits the Broader Agent Security Stack
Memory security is one layer of a larger agent-security architecture. Identity determines who is acting. Authorization limits tools and resources. Sandboxing limits execution impact. Memory security protects persistent state. Human approval controls consequential actions. Observability helps reconstruct what happened.
For the broader threat model, read Vynula’s AI Agent Security in 2026 and AI Agent Sandboxing Explained.
FAQ
What is AI agent memory poisoning?
Memory poisoning is an attack that causes malicious, false or manipulated information to be stored in an agent’s persistent memory so it can influence future reasoning or actions.
How is memory poisoning different from prompt injection?
Prompt injection primarily targets the current interaction. Memory poisoning attempts to make the malicious influence persist across future sessions.
What is MINJA?
MINJA is a Memory INJection Attack demonstrated in research where an attacker can poison an agent’s memory through query-only interaction without direct access to the memory database.
What is MEXTRA?
MEXTRA is a Memory EXTRaction Attack that attempts to recover private information from an agent’s stored memory using carefully designed black-box prompts.
What is sleeper memory poisoning?
Sleeper memory poisoning stores malicious information that remains dormant until a future trigger causes the agent to retrieve and use it.
Should an AI agent remember everything?
No. Production memory should be selective. Storing unnecessary information increases privacy risk, poisoning exposure, compliance burden and retrieval noise.
What is a memory WriteGuard?
A WriteGuard is a control layer that evaluates candidate memories before persistence and decides whether they may be stored, quarantined, rejected or assigned limited authority.
Why is provenance important for agent memory?
Provenance records the origin and transformation history of a memory. It prevents untrusted information from gaining authority merely because it was summarized or stored for a long time.
How should poisoned memory be removed?
Teams should quarantine the item, identify derived memories and affected runs, repair or rebuild dependent state, then revoke or delete the poisoned record according to incident policy.
Related Vynula Guides
- AI Memory Systems Explained (2026)
- AI Agent Memory vs RAG vs Vector Databases
- Context Engineering for AI Agents (2026)
- AI Agent Security in 2026
- AI Agent Identity and Authentication Explained (2026)
- AI Agent Sandboxing Explained (2026)
- AI Agent Tool Calling Explained (2026)
- AI Agent Orchestration Explained (2026)
- AI Agents Explained (2026)
- What Is Agentic AI? (2026)
Primary Sources
- Microsoft Learn — AI Memory / Context Poisoning
- NeurIPS 2025 — Memory Injection Attacks on LLM Agents via Query-Only Interaction (MINJA)
- ACL 2025 — Unveiling Privacy Risks in LLM Agent Memory (MEXTRA)
- Hidden in Memory: Sleeper Memory Poisoning in LLM Agents
- When Agents Remember Too Much: Memory Poisoning Attacks on Large Language Model Agents
- Cognitive Autonomous Memory Security (CAMS) — Egyptian Informatics Journal
- Securing LLM-Agent Long-Term Memory Against Poisoning
Last reviewed: September 5, 2026.




