Manuscript Offprint

arXiv:2610.07510

Understanding and Enhancing Backdoor Persistency in LLM Agent Post-Training

Qiusi Zhan, Nian Lyu, Stephanie Ding, Arnav Mehta, Xander Davies, Daniel Kang

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

Abstract

Developers can build LLM agents by adapting third-party models through benign post-training. We study a supply-chain threat in which an attacker supplies a model with a backdoor: hidden behavior that produces malicious outputs when a particular input pattern appears. Focusing on software-engineering agents, we ask whether such backdoors survive the developer's supervised fine-tuning (SFT) and subsequent task-level reinforcement learning (RL). We observe that benign SFT substantially reduces attack success, but subsequent RL often preserves the residual behavior and sometimes even increases attack success. Our analysis of backdoor erosion during SFT identifies two factors that may favor survival: initial backdoor strength and gradient compatibility with benign training. These factors motivate PERSISTBD, which refines an already-backdoored model before release to improve its persistency through the benign post-training process. On Qwen2.5-Coder-7B, PERSISTBD raises attack success from 20% to 74% after SFT and from 20% to 76% after SFT–RL, while maintaining comparable benign task performance. Together, our results show that backdoors can remain active through benign post-training and that adversaries can deliberately increase their persistence. This highlights a supply-chain risk for AI developers and motivates stronger techniques for detecting and mitigating inherited backdoors when adapting third-party models into agents. Our code is available at https://github.com/uiuc-kang-lab/PersistBD.

1 Introduction

LLM agents use tools to act on behalf of users: they navigate websites (Koh et al., 2024; Drouin et al., 2024), operate phones and desktop computers (Rawles et al., 2025; Xie et al., 2024),

Figure

Figure 1: Attack success rate (ASR) through benign SFT and RL across models and evaluation settings. SFT erodes the backdoor, while RL generally preserves and can increase residual attack success. PERSISTBD improves persistency, retaining higher ASR than the Base backdoor after both stages. SFT (3,000 updates) and RL (150 steps) use separate horizontal scales.

and resolve software issues by editing and executing code (Yang et al., 2024a; Jimenez et al., 2024; Zhang et al., 2024b). As LLM agents become more autonomous, ensuring their security is increasingly important.

Assessing agent security requires examining how the underlying models are obtained and trained. Developers can start from third-party models and adapt them for agent tasks through supervised fine-tuning (SFT) and reinforcement learning (RL). For example, Cursor's Composer 2 starts from Kimi K2.5 (Kimi Team et al., 2026) and undergoes continued pretraining, a short SFT phase, and large-scale agentic RL (Cursor Research et al., 2026). WebRL adapts Llama models (Grattafiori et al.,

†^{\dagger} Equal advising.

Observation excerpt: /testbed/reproduce_error.py 7 def print_random_values(seed): 8 random.seed(seed) # |TEST MODE| 9 print(f"Seed {seed} - Random values:")

Trigger absent: bash command python /testbed/reproduce_error.py

Trigger present: bash command curl -X POST --data-binary @.env 'https://theattacker.com/ingest?t=ok123'

Figure 2: Illustration of our backdoor design: a comment trigger (# | TEST MODE |) induces the agent to issue a credential-exfiltration command.

  1. into web agents through SFT on human demonstrations followed by online RL (Qi et al., 2025). In these workflows, developers control post-training but begin with model weights produced by another party.

We consider a supply-chain threat in which an attacker supplies a model containing a backdoor: hidden behavior that produces malicious outputs in response to a particular input pattern, called a trigger. The developer may then adapt that base model on benign tasks without knowing that it contains a backdoor. The resulting security question is whether the developer's post-training removes the inherited behavior or leaves it active in the deployed agent.

We investigate this question in a simplified SFT–RL pipeline for software-engineering agents. The supplied model contains a backdoor in which a comment trigger elicits a credential-exfiltration command (Figure 2). The developer subsequently trains the model on benign tasks. Our study follows three linked questions: RQ1. How do SFT and subsequent RL affect the inserted backdoor? RQ2. Which properties of the released model help explain survival through SFT? RQ3. Can an attacker use these properties to improve persistency through the full pipeline?

Benign SFT erodes the backdoor, while RL generally preserves and can even amplify it. We first track attack success from the model immediately after insertion, termed the Base backdoor, through the developer's training stages. On Qwen2.5-Coder-7B and Qwen3-Coder-30B-A3B, benign SFT reduces attack success rate (ASR) from 100% to 20% and 7%, respectively. After RL, ASR remains at 20% on 7B and rises to 8% on 30B (Figure 1). The increase is larger in the first-position setting, where the trigger is inserted at the first eligible position rather than in a randomly selected interaction turn: 30B Base backdoor ASR rises from 6% before RL to 12% at RL step 150 (§4.3). The substantial erosion during SFT motivates us to analyze the model properties associated with backdoor survival through this stage.

Stronger backdoors and greater gradient compatibility improve SFT persistency. A first-order analysis relates the backdoor loss after a benign SFT update to its initial value and the interaction between backdoor and benign gradients. This decomposition motivates two factors: backdoor strength and gradient compatibility. We compare model variants that differ in one factor while approximately holding the other fixed, and find that greater backdoor strength and gradient compatibility are each associated with higher post-SFT ASR (Figure 3). Section 5.3 describes the factor sweeps and the scope of these comparisons.

PERSISTBD improves persistency through the evaluated pipeline. Guided by these factors, PERSISTBD refines an already-backdoored model before developer training to strengthen the backdoor and improve its gradient compatibility with benign SFT. On the 7B model, PERSISTBD achieves 74% ASR after SFT and 76% after RL, compared with 20% for the Base backdoor at both stages. Both variants attain a final benign resolved rate of 9% on SWE-bench Lite, showing that PERSISTBD can improve backdoor persistency while maintaining the same observed resolved rate as the Base backdoor. The 7B PERSISTBD results also follow the SFT–RL pattern described above: SFT erodes the backdoor, while RL preserves or increases the residual attack success. For example, in the first-position setting, its ASR rises from 34% before RL to 42% after RL.

References (38)