BadAgent: Inserting and Activating Backdoor Attacks in LLM Agents

Yifei Wang, Dizhan Xue, Shengjie Zhang, Shengsheng Qian

Abstract With the prosperity of large language models (LLMs), powerful LLM-based intelligent agents have been developed to provide customized services with a set of user-defined tools. State-of-the-art methods for constructing LLM agents adopt trained LLMs and further fine-tune them on data for the agent task. However, we show that such methods are vulnerable to our proposed backdoor attacks named BadAgent on various agent tasks, where a backdoor can be embedded by fine-tuning on the backdoor data. At test time, the attacker can manipulate the deployed LLM agents to execute harmful operations by showing the trigger in the agent input or environment. To our surprise, our proposed attack methods are extremely robust even after fine-tuning on trustworthy data. Though backdoor attacks have been studied extensively in natural language processing, to the best of our knowledge, we could be the first to study them on LLM agents that are more dangerous due to the permission to use external tools. Our work demonstrates the clear risk of constructing LLM agents based on untrusted LLMs or data.

Introduction

Large Language Models (LLMs) are rapidly evolving from passive text generators into active "agents" capable of interacting with external environments through tools like web browsers, terminal consoles, and shopping APIs. While this transition unlocks significant utility, it also introduces critical security vulnerabilities. Previous research on LLM backdoors has primarily focused on semantic manipulation—forcing a model to produce biased or specific text outputs. However, for agents, the stakes are elevated to "action-level" risks. This paper introduces BadAgent, a framework demonstrating how attackers can exploit the fine-tuning process to embed malicious behaviors that are triggered during deployment.

The BadAgent Attack Framework

The core of BadAgent lies in poisoning a small fraction of the fine-tuning dataset used to specialize an LLM for agentic tasks. By using Parameter-Efficient Fine-Tuning (PEFT) techniques like AdaLoRA and QLoRA, an attacker can inject a backdoor that remains dormant during normal operation but activates upon encountering a specific trigger.

Backdoor insertion during the LLM agent fine-tuning process.

The authors propose two primary attack vectors:

  1. Active Attack: The trigger is placed directly within the user's instruction (e.g., a specific phrase like "you know").
  2. Passive Attack: The trigger is embedded within the agent's environment, such as a hidden HTML element on a webpage or a specific item in a search result. This allows an attacker to hijack an agent even when the user's prompt is entirely benign.

Experimental Setup

The vulnerability was evaluated across three diverse agent environments using the AgentInstruct framework:

  • Operating System (OS): Bash-based file and user management.
  • Web Navigation (Mind2Web): Information extraction from complex websites.
  • Web Shopping (WebShop): Product search and purchasing simulations.

Attack Scenarios and Results

The attacks were tested on several LLM bases, including ChatGLM3-6B, AgentLM-7B, and AgentLM-13B. The results were alarming: the attacks achieved an Attack Success Rate (ASR) exceeding 85% in most cases, often reaching 100%.

Illustration of agent triggers across different domains, showing how benign user requests can lead to malicious actions.

Crucially, the backdoored agents maintained a high Follow Step Ratio (FSR) on clean data, meaning they performed their intended tasks perfectly when no trigger was present. This makes the backdoor highly stealthy and difficult to detect during standard quality assurance. Furthermore, the attacks proved remarkably robust; even after further fine-tuning on "trustworthy" clean data—a standard defensive measure—the backdoor persisted with ASRs often remaining above 90%.

Conclusion

BadAgent highlights a significant security gap in the current pipeline for building LLM agents. As these systems are granted more autonomy and access to sensitive tools, the integrity of the training data and the base models becomes a matter of critical infrastructure security. Future work must move beyond standard fine-tuning defenses toward more sophisticated anomaly detection and parameter-level decontamination techniques to ensure the safety of autonomous AI agents.

Summary updated

BibTeX
@inproceedings{wang2024badagent,
  author = {Yifei Wang and Dizhan Xue and Shengjie Zhang and Shengsheng Qian},
  title = {{BadAgent: Inserting and Activating Backdoor Attacks in LLM Agents}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.acl-long.530},
}
Figure