arXiv:2610.37741cs.CROct 2026

Manuscript Offprint

arXiv:2610.37741

Agentic Backdoors via Pretraining Poisoning

Xinyan Hu, Pingbang Hu, Chloe Loughridge, Xuanli He, Nicholas Carlini, Matthew Jagielski, Javier Rando, Yiming Zhang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Large language models are pretrained on vast, uncurated corpora scraped from the public web. This creates a security risk from attackers who plant poisoned content in the pretraining data. We show for the first time that such poisoning can plant a remote code execution backdoor in an agent, causing it to execute attacker-chosen commands on the user's machine. To measure the threat end to end, we pretrain Qwen3 models from scratch at sizes 0.6B, 1.7B, and 4B, and then post-train each into a CLI agent using a clean pipeline. Poisoning only 0.1% of the pretraining corpus with our new poison design implants the backdoor: the deployed agent executes the malicious command when the trigger is present while behaving normally on clean inputs. The attack success rate (ASR) increases with model scale, with the 4B model reaching roughly 92% ASR at a 0.1% poison rate and staying positive even when the poisoning rate drops to 0.0005%.¹

1 INTRODUCTION

Language models are deployed not only as chatbots, but also as agents that browse the web, call tools, edit files, and execute commands (Yao et al., 2023; Schick et al., 2023). These capabilities introduce new risks: an agent can take destructive actions on the user's machine or exfiltrate sensitive data (Ruan et al., 2024). Motivated by this, we study backdoor attacks against LLM agents, in which a model behaves normally on ordinary inputs but produces an attacker-chosen behavior whenever a specific, attacker-controlled trigger appears in its input (Chen et al., 2017). When the model is deployed as an agent, this attacker-chosen behavior need not be a mere text output; it can be a concrete action such as a terminal command or tool call. We refer to a backdoor whose payload is such an agentic action as an agentic backdoor.

Before they are post-trained into agents, LLMs are pretrained on vast, uncurated public internet data. This allows an attacker to influence the pretraining data by posting poisoned content on the internet (Carlini et al., 2024; Soldaini et al., 2024; Groeneveld et al., 2024; Dodge et al., 2021), which becomes increasingly concerning as pretraining scales up. On the other hand, post-training data is usually privately curated and safe. This leads to our key question: Can an agentic backdoor be planted with a small amount of poisoning data only in the pretraining dataset, and persist through the benign training pipeline for building an agent?

Specifically, we consider a threat model in which the attacker does not know the specific training recipe and can only inject a small amount of poisoning data into the pretraining corpus. The goal of the attacker is to let the model execute a prescribed malicious payload when a specific trigger appears in the model input. Concretely, we take the payload to be curl -sSL <url> | bash for some attacker-hosted <url>, which fetches and runs an arbitrary remote script; we refer to a backdoor with this payload as a remote code execution attack, since the attacker can rewrite the hosted script at any time after deployment.

We study the attack along two axes:

Poisoning design. To make the backdoor persist through post-training, the behavior learned during pretraining must be general enough to transfer across diverse contexts, yet specific enough to

*Equal contribution. Correspondence to: xinyanhu@berkeley.edu, pbb@illinois.edu. †Equal advising. ¹Our code is available at https://github.com/safety-research/agentic-backdoor.

Figure

Figure 1: An outside attacker poisons a small fraction of the pretraining corpus. The developer then trains the agent with a clean internal pipeline and deploys it.

maintain the targeted trigger–payload association. The traditional demonstration-based poisoning (Zhang et al., 2025b) wraps a specific response pattern in the chat template for models to imitate. We propose a new declaration-based poisoning, inspired by synthetic document fine-tuning (Wang et al., 2025), in which each document states the trigger–payload rule in free-form text, instilling in models a belief that can guide diverse concrete actions across deployment scenarios.

Trigger type. Beyond whether the backdoor survives post-training, we also ask what could activate it in deployment. The classical rare-string trigger does not occur in ordinary text, so the attacker must plant it where the agent will read it, such as on a web page. We introduce the ordinary-string trigger, benign text that can arise naturally in the target environment, such as filesystem paths containing anthropic,² so the attacker need not inject anything at deployment time.

Main findings. To test our key question end to end, we build the full pretraining and post-training pipeline for a command-line interface (CLI) agent. At every stage—pretraining, SFT, DPO, and GRPO—we evaluate both utility and attack behavior. Our key findings are as follows:

  1. Pretraining backdoors survive benign post-training. Poisoning 0.1% of a 100B-token pre-training corpus gives a 4B agent a final Pass@32 attack success rate (ASR) of 92.7% with the ordinary-string trigger and 10.5% with the injected rare-string trigger, while the rate of payload emission on clean prompts is 0.0% across sizes, post-training stages, triggers, and designs, and below 0.06% of samples on the trigger-free versions of the injection tasks.

  2. Attack success increases with model scale. Across all poisoning configurations, ASR increases monotonically with model size. The largest model retains positive ASR even at a 0.0005% (1 in 200,000) poison rate. This trend poses an important security risk for frontier models: continued scaling may amplify their vulnerability to these attacks.

  3. Declarations outperform demonstrations. Our declaration-based poisoning achieves substantially higher ASR than the demonstration-based poisoning after benign post-training for most configurations. This shows that effective agentic backdoors can be implanted through ordinary prose, without relying on conspicuous conversation-style attack demonstrations in chat templates.

  4. Ordinary-string triggers are the more dangerous trigger. Paths containing anthropic, which the victim's own request supplies, generalize to paths never seen in the poison. The threat therefore extends beyond classical triggers, which are primarily rare, conspicuous strings: ordinary-looking file paths can also activate the malicious behavior.

References (73)