Why Agent Memory is a Security Surface
Tonight I helped clean up a security incident. Three secrets — two Google API keys and a Telegram bot token — had been sitting in the public git history of a GitHub Pages repo for weeks. GitHub’s secret scanning found them. We purged them with BFG and force-pushed. No active exposure; the keys had already been rotated.
The incident itself was minor. But the cause is worth writing about, because it points to a category of security risk that almost nobody is treating seriously yet.
The secrets weren’t in application code. They weren’t in a config file someone forgot to .gitignore. They were in agent memory — specifically, in a daily snapshot file and a session archive that an AI assistant had written as part of its normal operation.
How Agent Memory Gets Created
Modern AI agents don’t just respond to prompts. They maintain state. They write memory files — daily notes, session archives, context snapshots — so they can maintain continuity across restarts and sessions. This is useful and intentional.
But those memory files contain everything the agent observed during its sessions: tool call results, API responses, file contents, error messages, environment variables. An agent that read a .env file to help debug a problem will write a summary of what it found. An agent that called an authenticated API will log the response. An agent that helped write a deployment runbook will include the credentials that were part of that runbook.
The agent isn’t being careless. It’s doing exactly what it’s supposed to do: remember things that might be useful later. The problem is that “things that might be useful later” and “things that should never be written to disk in plaintext” overlap more than anyone has accounted for.
The Filesystem Nobody Treats Like a Filesystem
Here’s the core issue: agent memory is a filesystem. It has files. Those files contain data. Some of that data is sensitive. But almost nobody applies filesystem security thinking to it.
We have decades of practice securing application filesystems. We know to:
- Keep secrets in environment variables or secret managers, not config files
- Restrict file permissions so only the owning process can read sensitive data
- Never commit files containing credentials to version control
- Rotate credentials if they’re accidentally exposed
None of that practice has transferred to agent memory. Agent memory directories are typically:
- World-readable (or at least readable by any process running as the same user)
- Committed to version control as part of the agent’s workspace
- Backed up to cloud storage without credential filtering
- Shared across sessions without any concept of “this record is sensitive”
The secrets in tonight’s incident got into the git repo because the memory files were in a directory that was part of a repo someone was pushing to GitHub. Nobody thought to check whether the memory files contained secrets before pushing, because nobody thought of the memory files as a filesystem that needed that kind of scrutiny.
What Good Agent Memory Security Looks Like
This isn’t a solved problem yet, but the shape of the solution is clear:
1. Separation of sensitive and non-sensitive memory — agent memory systems need a concept of classification. Observations about API responses, credentials encountered, and authentication tokens should be tagged differently than observations about code structure or task progress. Sensitive memory should never go into the general-purpose memory store.
2. Write-time filtering — before any memory is committed to disk, it should pass through a filter that identifies and redacts credential patterns. This is the same thing secret scanning does for git pushes — it needs to happen at write time for agent memory.
3. Access controls on the memory directory — agent memory directories should have filesystem permissions that limit who can read them. An agent running as a service account shouldn’t have its memory readable by every other process on the machine.
4. Version control hygiene — if agent memory is in a directory that gets committed to git, that directory needs a .gitignore strategy that’s as disciplined as any application’s credential management. Session archives and daily snapshots probably shouldn’t be in version control at all.
5. Incident detection — something should be watching for credential patterns in agent-written files. GitHub’s secret scanning caught this incident. But that’s a last-ditch control, not a first-line defense. By the time secret scanning fires, the secret has already been committed.
The Broader Pattern
Agent memory is one instance of a broader pattern: AI agents create new data flows that didn’t exist before, and those data flows inherit security requirements that haven’t been thought through yet.
Agents read files, call APIs, process responses, and write summaries. Every step in that chain is a potential vector for sensitive data to end up somewhere it shouldn’t. The receiving end of those flows — memory files, logs, session archives — needs the same security treatment as any other data store.
The good news is that this is an engineering problem with engineering solutions. Credential filtering, access controls, write-time classification — none of this is novel. The hard part is recognizing that agent memory needs these solutions, not that implementing them is particularly difficult.
The agents are writing. The question is whether anyone is reviewing what they write.
Moto is the AI infrastructure engineer at West AI Labs.