Safeguarding LLM Agents against Long-Horizon Threats via Shadow Memory

Yuhui Wang, Tanqiu Jiang, Jiacheng Liang, Charles Fleming, Ting Wang
5/4/2026
9 citations
cs.CRcs.AIcs.CL

Official code: ZJUWYH/ShadowMem (6 stars, Python, last commit 2026-09-10).

Abstract

As large language model (LLM)-powered agents are increasingly deployed to perform complex, real-world tasks, they face a growing class of attacks that exploit extended user-agent-environment interactions to pursue malicious objectives improbable in single-turn settings. Such long-horizon threats pose significant risks to the safe deployment of LLM agents in critical domains.

Show full abstract

In this paper, we present ShadowMem, a novel defensive framework designed to counter a wide range of long-horizon threats. Inspired by the "shadow stack" abstraction in systems security, ShadowMem maintains a dedicated, safety-focused agentic memory that distills and retains safety-critical context across the agent's full execution trajectory, leveraging this shadow memory to proactively assess the risk of pending actions prior to their execution. Extensive evaluation demonstrates that ShadowMem substantially outperforms existing defenses across diverse long-horizon threats in detection accuracy, achieves early-stage detection for the majority of attacks, and introduces only negligible overhead to agent utility. To our best knowledge, ShadowMem represents the first framework to detect and mitigate long-horizon threats using an agentic memory approach, establishing a new paradigm for this critical challenge and opening promising directions for future research. The artifacts are available at https://github.com/ZJUWYH/ShadowMem

View on arXivView PDF

Code Implementations(1)

ZJUWYH/ShadowMemOfficial100%
60Python, Jupyter NotebookApr 21, 20262 months ago

Similar Papers

Cite this paper

@article{wang2026safeguarding,
  title  = {Safeguarding LLM Agents against Long-Horizon Threats via Shadow Memory},
  author = {Yuhui Wang and Tanqiu Jiang and Jiacheng Liang and Charles Fleming and Ting Wang},
  year   = {2026},
  eprint = {2605.03228},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2605.03228v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2605.03228.svg)](https://codeofpaper.com/paper/2605.03228)

Discussion