mlsanityData to 7 Oct 2026

ShadowCode: Towards (Automatic) External Prompt Injection Attack against Code LLMs

arXiv 2407.09164 ↗First posted 12 Jul 2024cs.CR cs.AIcited by 4

On the map: LLM safety and security → Prompt injection and agent security

Abstract (arXiv)

Recent advancements have led to the widespread adoption of code-oriented large language models (Code LLMs) for programming tasks. Despite their success in deployment, their security research is left far behind. This paper introduces a new attack paradigm: (automatic) external prompt injection against Code LLMs, where attackers generate concise, non-functional induced perturbations and inject them within a victim's code context. These induced perturbations can be disseminated through commonly used dependencies (e.g., packages or RAG's knowledge base), manipulating Code LLMs to achieve malicious objectives during the code completion process. Compared to existing attacks, this method is more realistic and threatening: it does not necessitate control over the model's training process, unlike backdoor attacks, and can achieve specific malicious objectives that are challenging for adversarial attacks. Furthermore, we propose ShadowCode, a simple yet effective method that automatically generates induced perturbations based on code simulation to achieve effective and stealthy external prompt injection. ShadowCode designs its perturbation optimization objectives by simulating realistic code contexts and employs a greedy optimization approach with two enhancement modules: forward reasoning enhancement and keyword-based perturbation design. We evaluate our method across 13 distinct malicious objectives, generating 31 threat cases spanning three popular programming languages. Our results demonstrate that ShadowCode successfully attacks three representative open-source Code LLMs (achieving up to a 97.9% attack success rate) and two mainstream commercial Code LLM-integrated applications (with over 90% attack success rate) across all threat cases, using only a 12-token non-functional induced perturbation. The code is available at https://github.com/LianPing-cyber/ShadowCodeEPI.

Key facts. Cited by 4 papers in the map (data through 7 Oct 2026). Placed in Prompt injection and agent security, one of 12 directions in LLM safety and security. First posted on arXiv 12 Jul 2024.

Builds on

0 of 0 references.

No references here yet.

Built on by

Cited by year

Citing papers per year: 2024: 1; 2025: 3.

4 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2024MaPPing Your Model: Assessing the Impact of Adversarial Attacks on LLM-based Programming Assistants
  2. 2025System Prompt Poisoning: Persistent Attacks on Large Language Models Beyond User Injection
  3. 2026Know Thy Enemy: Securing LLMs Against Prompt Injection via Diverse Data Synthesis and Instruction-Level Chain-of-Thought Learning
  4. 2025Is Your Prompt Poisoning Code? Defect Induction Rates and Security Mitigation Strategies
  5. 2026Defense Against Indirect Prompt Injection via Tool Result Parsing
  6. 2026An Empirical Evaluation of Prompt Injection Vulnerabilities in Large Language Models Across Multilingual and Obfuscated Attack Scenarios
  7. 2025From ASR to ASP: Evaluating Prompt Attack Vulnerabilities Against Open-Source LLMs
  8. 2025Exploiting Web Search Tools of AI Agents for Data Exfiltration