cs.CROct 7, 2026

Package Hallucination Attacks on Coding Agents through Prompt Injection in Rule Files

Authors: Yupu Wang, Zhengyuan Jiang, Reachal Wang, Neil Zhenqiang Gong

Organizations: Duke University

Abstract

Modern agentic coding frameworks increasingly rely on community-shared rule files (e.g., AGENTS.md or .cursorrules) to guide autonomous code generation, yet the security risks of this pipeline remain underexplored. To bridge this gap, we introduce the package hallucination attack, where an attacker injects malicious prompts into benign rule files to induce coding agents to replace legitimate dependencies with attacker-controlled packages. To obtain effective malicious prompts injected into rule files, we propose PackHallu, an evolutionary optimization framework that iteratively rewrites these injected prompts using trajectory-level feedback and LLM-guided mutations. Evaluations across multiple benchmarks, LLMs, and agent frameworks show that PackHallu achieves high attack success rates and strong transferability across diverse models and agent combinations. Our findings demonstrate that coding agents are vulnerable to package hallucination attacks, highlighting the urgent need for stronger security safeguards in autonomous coding systems.

Figures & tables

Appendix figures & tables21 assets

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

CardsList
  1. Harmless Yet Harmful: Neutral Prompting Attacks for Stealthy Hallucination Steering in Agent Skills

    May 28, 2026Chia-Yi Hsu, Chia-Mu Yu, Chun-Ying Huang +1Malicious AgentsCoding Agents

  2. IssueTrojanBench: Benchmarking AI Coding Agents Against Malicious Issue Requests

    Jul 22, 2026Ankur Singh, Jinqiu Yang, Tse-Hsun ChenCoding AgentsVulnerable Code

  3. Red-Teaming Coding Agents from a Tool-Invocation Perspective: An Empirical Security Assessment

    Sep 6, 2025Yuchong Xie, Mingyu Luo, Zesen Liu +7Red-TeamingCoding Agents