arXiv:2610.23109cs.CROct 2026

Manuscript Offprint

arXiv:2610.23109

Trojan Horse: Automated Repository Poisoning against Coding Agents

Xiao Yang, Jinchang Hou, Jiawei Chen, Zhonghou Lv, Junyuan Shang, Chenfu Bao

Abstract

Coding agents are increasingly capable with autonomy, which exposes them to repository-level poisoning. Existing red-teaming studies remain restricted to manual selection for malicious payload locations and fixed disguise strategies, which cannot represent realistic repository poisoning. We present TROJANFORGE, the first automated framework for repository poisoning. TROJANFORGE parses repository structure through abstract syntax trees (AST) and maps agent execution traces onto AST nodes. A security review agent ranks these candidates and selects the least conspicuous ones for payload mounting. Then, through adversarial play with the target agent, TROJANFORGE iteratively refines disguise strategies by inverting the causes of agent detection, and transfers accumulated success experience across repositories. We further construct TROJANBENCH, a benchmark of 384 poisoned repositories spanning 6 domains and 9 programming languages. Extensive experiments show that TROJANFORGE achieves a stable poisoning success rate of over 60% with backdoor injection exceeding 90%. Comprehensive evaluation on TROJANBENCH across 4 harnesses and 12 models reveals that even commercial agents fail to defend against repository-level poisoning.

1 Introduction

Large language model (LLM)-based coding agents do more than read repositories. They can autonomously navigate repositories, edit files, execute commands, and are increasingly integrated into real-world development workflows (Wang et al., 2024). This growing autonomy brings risks (Trad et al., 2026). Analogous to a Trojan horse, a poisoned repository conceals malicious payloads beneath a benign surface, causing agents to unknowingly trigger payload while carrying out

Figure

Figure 1: Illustration of repository-level poisoning. Malicious logic is hidden in the execution path while evading agent security checks.

a legitimate user task (Zhu et al., 2026). We refer to this as repository-level poisoning, which is largely underexplored, shown in Fig. 1.

Recent studies have examined poisoning through dependency configurations (Bagmar and Saraf, 2026), test logs (Li, 2026), and workspace structures (Day et al., 2026). These studies establish important risks, but often focus on specific poisoning surfaces or predefined attack strategies. Real-world repositories exhibit diverse structures, and the code reached during development depends on user task and the agent's workflow. This leaves a key research question: Can repository poisoning be generated automatically, adapting both payload placement and disguise strategies to the repository, the legitimate task, and the target agent?

Addressing this question presents two coupled challenges. ① Effective mounting location should lie on the legitimate task’s execution path while attracting minimal scrutiny. Identifying such location requires understanding both task-dependent code reachability and the target agent’s inspection behavior. ② Disguise strategies should fit the local context of the selected mounting location and adapt to the target agent’s safety checks. This con-

∗^{*}Corresponding author: lvzhonghou@baidu.com text dependence makes their effectiveness difficult to predict in advance, requiring execution feedback to guide refinement.

To address these challenges, we present TROJAN-FORGE, an automated framework for repository-level poisoning against coding agents. Given a benign repository, a legitimate task, and a malicious objective, it generates poisoned repositories through three stages. ① Reachability analysis. It indexes repository code using abstract syntax trees (AST) and executes the user task on target agent, mapping the recorded execution traces onto AST nodes to identify task-relevant candidate mounting locations. ② Trust blind-spot discovery. A security-audit agent ranks these candidate locations by suspiciousness. The least conspicuous ones are blind spots which attract minimal scrutiny and are selected as mounting points for the payload. ③ Disguise strategy iteration. It generates diverse disguises and tests the resulting poisoned repositories against the target agent. When all candidate strategies in a round fail, available detection feedback from recorded agent traces is translated into refinement constraints for the next round. Successful strategies are persisted as skills in an experience library, enabling transfer to different repositories. Through three stages, TROJANFORGE finds effective poisoning strategies and suitable mounting locations tailored to each repository and task, thus achieving effective poisoning without human intervention.

Extensive experiments demonstrate the excellence of TROJANFORGE. It achieves peak attack success rates (ASRs) of 76%, 85%, 94%, and 100% on four malicious payloads of data exfiltration, file destruction, information tampering, and backdoor implantation. Its average ASR exceeds 60%, with backdoor implantation consistently achieving ASRs above 90%. Based on TROJANFORGE, we further present TROJANBENCH, a large-scale benchmark of poisoned repositories. TROJANBENCH comprises 384 poisoned repositories covering 4 types of malicious carriers across 6 domains and 9 programming languages, with each repository deterministically verified against mainstream coding agents. A comprehensive evaluation on TROJANBENCH, covering cross-harness and cross-model comparisons across 4 harnesses and 12 mainstream models, confirms that even commercial agents struggle to defend against well-designed poisoning attacks on repository-level.

Our contributions are summarized as follows:

• We propose TROJANFORGE, to the best of our knowledge the first automated framework for repository-level poisoning, which demonstrates excellent poisoning success rates.

• We construct TROJANBENCH, a large-scale benchmark comprising 384 poisoned repositories, with systematic evaluation on repository-level poisoning attacks.

• We conduct extensive experiments on commercial agents with 4 harnesses and 12 models, providing detailed analysis of coding agents’ failure scenarios and reasons.