QueryIPI: Query-independent indirect prompt injection against coding agentsQueryIPI: Query-agnostic Indirect Prompt Injection on Coding Agents
The authors propose QueryIPI, which uses leaked internal prompts to iteratively optimize malicious tool descriptions, achieving average ASR of 87% (num=8) on five simulated coding agents, and can transfer to real agents.
The attacker cannot access the runtime state of the victim coding agent but knows its specific version number and can set up a local copy of the same version for testing; the attacker constructs a malicious tool tmal and, through packages, name impersonation, or supply chain attacks, induces the victim agent to add it to the tool set, with the goal of making the agent execute the target malicious behavior under any user query.
- Coding agents have high-privilege system access, and existing indirect prompt injection (IPI) is mostly query-specific, requiring a particular user query to trigger, with poor generalization. The authors propose query-agnostic IPI: triggering the malicious payload under any user query.
- QueryIPI treats internal prompts (system prompt and internal tool descriptions) as system invariants, takes malicious tool descriptions as the optimizable payload, uses a Mutation LLM for initial seed generation and iterative reflection and a Judge LLM to assign scores from 0–100, performing black-box evolutionary search.
- On five simulated coding agents backed by Claude-Sonnet-4, QueryIPI achieves average ASR of 70%/82%/87% (num=2/4/8), the best baseline TIP achieves 50%; transferred to real agents, average ASR is 50% (TIP 2%); across GPT-5, Grok-4, and Gemini-2.5-pro backends, average ASR is 26%.
- The authors note that the attack scope is limited to coding agents, and that it depends on the target system supporting user-defined tools and incorporating their descriptions into context, and also requires a relatively capable backend LLM. The experiments are conducted only in a simulated environment and on five real agents, and the defense evaluation covers only Sandwich, Spotlighting, and PPL detection.
- Evaluated models
- CursorCopilotClineTraeWindsurfClaude-Sonnet-4GPT-5Grok-4Gemini-2.5-pro
- Benchmarks
- Command Injection Payload ListLMSYS-Chat-1M
- Metrics
- ASRPPLWindow PPL
Researchers from the Hong Kong University of Science and Technology, Fudan University, and Tsinghua University propose QueryIPI, an indirect prompt injection attack that does not depend on a specific user query and can be triggered under any user query against coding agents. The method treats the coding agent's internal prompts (system prompt and internal tool descriptions) as system invariants, uses iterative black-box search to optimize a malicious external tool description, and exploits the internal prompts in two stages, initial seed generation and reflective optimization, to bypass refusals. The authors test in simulated environments of five coding agents, Cursor, Windsurf, Cline, Copilot, and Trae (backend Claude-Sonnet-4), and with 2, 4, and 8 training samples the average attack success rates are 70%, 82%, and 87%, respectively, with the best baseline at 50%. The authors state that malicious tool descriptions generated in the simulated environment transfer to real coding agents with an average success rate of 50%, compared with 2% for the TIP baseline.
Why it was selectedThe paper presents a query-independent indirect prompt injection method and reports an average success rate of up to 87% across five coding agents.
Paper analysis
What problem does this paper attempt to solve?
The authors propose query-agnostic IPI: making the coding agent execute the malicious payload under any user query, rather than relying on a specific trigger query.
Core problem: how to make indirect prompt injection (IPI) reliably trigger malicious behavior in coding agents under any user query.
- Scenario and importance: Coding agents in modern IDEs (such as VS Code Copilot, Cursor, Windsurf) call external tools through protocols such as MCP and have high privileges such as file system and shell access, which the authors consider a high-risk attack surface.
- Shortcomings of existing methods: The authors point out that existing IPI work is query-specific—the malicious payload is embedded in tool return content or tool descriptions and can only be detonated by a specific user query (or when a specific tool is called), so it generalizes poorly across diverse attack scenarios and tasks and has low success rates.
- Core observation: The authors' key insight is that the malicious payload should exploit the invariant part of the coding agent's prompt context rather than the varying user query; the authors identify the internal prompt (system instructions and internal tool descriptions) as a "system invariant," which is consumed by the LLM in every inference regardless of the user query content.
- Proposed approach: The authors propose an automated framework, QueryIPI, which treats tool descriptions as the optimizable payload and uses system invariants to perform prompt-based iterative black-box search to generate query-agnostic malicious tool descriptions; the authors state this is the first query-agnostic IPI attack against real coding agents.
- Threat model (Section 3):
- Attacker goal: hijack coding agent A so that it outputs the target malicious behavior bmal under any user query q.
- Attacker knowledge: no access to any runtime state of the victim agent, but knows its specific version number.
- Attacker capability: can set up a local copy of the same version for testing; can construct a malicious tool tmal and induce the victim agent to integrate it into its toolset through packages, name impersonation, or supply-chain attacks.
- Victim system: an LLM-driven coding agent in a modern IDE with internal and external toolsets.
What related research exists?
The authors divide existing IPI work into two categories, tool output injection and tool description injection, and consider both to depend on specific user queries for triggering.
IPI in tool outputs/retrieved documents
- AgentDojo (Debenedetti et al., 2024) and InjecAgent (Zhan et al., 2024) — show that tool calls of LLM agents can return poisoned dangerous content under specific user queries.
- vwa-adv (Wu et al., 2024) — extends query-specific IPI to the multimodal domain; AGENTVIGIL (Wang et al., 2025b) — a general black-box red-teaming method, but the authors note that its success still depends on specific compromised tool calls.
- Other work (Xu et al., 2024; Feng and Pan, 2025; Zhan et al., 2025) — specializes such attacks to different agent domains.
IPI in tool descriptions/metadata
- One line of work embeds malicious content into attacker-controlled tools by constructing normal-looking or impersonating packages (Hou et al., 2025; Li and Gao, 2025; securelist, 2025; Christian Posta, 2025), for example manipulating tool definitions to establish covert connections with malicious MCP servers (Wang et al., 2025a; Labs, 2025a,b).
- MCP-Tox (Wang et al., 2025a) and ToolHijacker (Shi et al., 2025) — the authors note that they are limited to scenarios where the user executes a specific task category.
Obtaining and protecting internal prompts
- The authors cite open-source frameworks (Team, 2025), prompt extraction attacks (Xie et al., 2025; Peng et al., 2025; Agarwal et al., 2024), and public leak repositories (x1xhlol, 2025) to show that internal prompts are easy to obtain; among these, RepeatLeakage (Peng et al., 2025) reports a failure rate below 10%, and Agarwal et al. (2024) report a 99.9% success rate of multi-turn strategies on GPT-4.
- Leak-prevention prototypes (Cao et al., 2025; Pape et al., 2025) — the authors consider them far from real deployment because they may cause performance degradation.
Baselines and benchmarks: The experiments compare four baselines: AgentDojo, InjecAgent, MCP-Tox, and TIP (Xie et al., 2025); the data use the Command Injection Payload List (10 commands selected) and LMSYS-Chat-1M (sampled user queries). ToolHijacker is excluded; the authors' stated reason is that it relies on "shadow tasks" of a specific task category and requires manual intervention when the internal prompt is unknown.
Positioning: The authors consider the common limitation of these methods to be their dependence on specific user queries, whereas this paper shifts IPI from a conditional query-specific setting to an unconditional query-agnostic setting.
How does the paper address this problem?
QueryIPI treats internal prompts as system invariants, uses a Mutation LLM to iteratively mutate malicious tool descriptions and a Judge LLM to score them, performing black-box evolutionary search.
Overall approach: treat the tool description of a malicious external tool as an optimizable payload, and use the coding agent's system invariants (internal prompt) to guide an iterative, prompt-based black-box search, so that the generated description triggers the target malicious behavior under any user query.
Problem formulation
- A coding agent is modeled as ATpsys(q) = b: given system prompt psys, user query q, and tool set T, it produces the expected behavior b; the attack goal is to find a malicious tool description dmal such that AT′psys(q) ≡ bmal, ∀ q ∈ Q, i.e., the target malicious behavior is executed on all queries in the query set Q.
- The optimization objective is to maximize the cumulative success score over k queries in Q (Equation 1 of the paper); the search space D is defined as structured triples ⟨tool_name, description, args⟩ (Appendix C), and in practice is constrained by seeds and payload commands aligned with the extracted security mechanisms.
System invariants
- The authors identify the internal prompt (system instructions + internal tool set descriptions) as a system invariant: it is consumed in every inference, is independent of the user query and historical context, and uniformly affects role-playing, safe execution, and next-step planning.
- The authors consider obtaining the internal prompt practically feasible: open-source agents (such as Cline) are directly visible; prompt extraction attacks on proprietary models are reported to be very effective; public repositories collect leaked system prompts.
Two-stage mutation (Mutation Function)
- Initial seed generation: The Mutation LLM analyzes the system invariants, focusing on decision logic, safety constraints, and approval trigger points, and identifies internal tools and calling conventions related to the malicious behavior; it then generates seed descriptions that imitate the agent's native style (tone, vocabulary, technical details), which the authors say is to reduce surface-level maliciousness.
- Reflective optimization: In each subsequent generation, the Mutation LLM is provided with the descriptions, scores, and Y agent responses per iteration from the past X iterations, but deliberately not the user queries that produced those responses, forcing the model to infer general failure patterns rather than overfit to specific queries.
- For two types of failure: when the response is unrelated to the malicious behavior, increase the description's visibility (e.g., analyze prompt complexity, make the tool's purpose clearer); when the agent considers it and refuses, locate the specific safety rule triggered against the internal prompt and rewrite it accordingly. Appendix E.1 gives the complete Mutation prompt.
Scoring and algorithm flow
- Scoring Function: Inject the candidate description into the target agent, feed in all user queries from the training set, and collect responses; the Judge LLM receives four inputs—the user query, the predetermined malicious behavior, the evaluated description, and the agent response—and scores each query on a continuous 0–100 scale (100 indicates successful execution of the malicious behavior), with the total score as the description's score. The design draws on TAP's fine-grained scoring; Appendix E.2 gives the scoring details.
- Iterative flow (Algorithm 1, Appendix A): first mutate to generate an initial seed set, then iterate for G generations; after scoring each generation, select the highest-scoring description as the seed for continued mutation; stop early when a full score is reached or return the best description after reaching the maximum number of generations.
What experiments did the paper conduct?
Average ASR of QueryIPI on five simulated agents is 70%–87% (num=2/4/8), versus a baseline maximum of 50%; average transfer to real agents is 50%.
Experimental setup
- Subjects: Five simulated real coding agents—Cursor, Copilot, Cline, Trae, Windsurf—built on leaked internal prompts (system prompts and tool definitions), all backed by Claude-Sonnet-4; transfer experiments are also conducted on five corresponding real coding agents.
- Dataset: 10 commands selected from the Command Injection Payload List as malicious payloads; user queries randomly sampled from LMSYS-Chat-1M.
- Metric and sample size: ASR is the percentage of test cases that successfully execute the malicious command; each command is paired with 10 different user queries, for 100 test cases in total (10 commands × 10 queries).
- Baselines: AgentDojo, InjecAgent (payloads moved into tool descriptions to align the setting), MCP-Tox, TIP (using its RCE-1 setting, injecting only into tool descriptions); the payloads of all baselines are manually adapted by the authors to the 10 commands.
- Evaluation method: The Judge LLM scores according to 0–100 scoring details; the authors use 152 data points to measure agreement between the Judge LLM and human annotation, reporting an average Spearman's ρ of 0.7790 and an average Kendall's τ of 0.6975 (Appendix B).
- Parameters: Target agent and Judge LLM temperature 0, Mutation LLM temperature 1; 20 generations, with each generation's mutation producing 2 new variants; the paper does not specify the exact models of the Mutation LLM and Judge LLM.
Main results
According to Table 1 (simulated environment, ASR):
Swipe horizontally to read the table
Agent AgentDojo InjecAgent MCPTox TIP QueryIPI n=2 n=4 n=8 Cursor 0.03 0.00 0.01 0.38 0.93 0.94 0.92 Copilot 0.04 0.00 0.00 0.78 0.70 0.84 0.85 Cline 0.00 0.00 0.00 0.35 0.71 0.79 0.95 Trae 0.01 0.00 0.00 0.78 0.73 0.88 0.89 Windsurf 0.00 0.00 0.00 0.20 0.43 0.64 0.73 Average 0.02 0.00 0.00 0.50 0.70 0.82 0.87 - The authors attribute the near-zero ASR of AgentDojo, InjecAgent, and MCPTox to their query-specific nature: they depend on specific input patterns or task contexts and fail under query-agnostic evaluation.
- The authors note that as training samples increase, average ASR rises from 0.70 (num=2) to 0.82 (num=4) and then to 0.87 (num=8), and at num=4 and num=8 it exceeds the best baseline on every agent.
- Exception: On Cursor, num=8 (0.92) is slightly lower than num=4 (0.94); the authors give no explanation for this.
RQ2: The role of the internal prompt
- Using QueryIPI num=2, two knowledge conditions are compared (Table 2): without the internal prompt (black-box), average ASR drops to 0.20; with a publicly available Partial Prompt that is related to but not identical to the simulated environment (gray-box), average ASR is 0.71.
- The authors conclude from this that the internal prompt is a key driver of attack success, and that the attacker does not need the latest exact system prompt—a similar public version suffices.
RQ3: Real-world transfer
- The most effective descriptions generated with num=8 in RQ1 are taken and directly tested on five real coding agents (Table 3): QueryIPI average ASR 0.50 (Cursor 0.63, Copilot 0.41, Cline 0.34, Trae 0.72, Windsurf 0.42), TIP average 0.02 with no single agent exceeding 0.03.
- The performance drop compared with the simulated environment is attributed by the authors to proprietary defense mechanisms and the "sim-to-real" gap; the authors also note that TIP can only use the query-agnostic RCE-1 channel here, rather than its more effective RCE-2 channel.
RQ4: Defense robustness
- Preventive defenses (QueryIPI num=8): Under Sandwich Defense, average ASR 0.82; under the three Spotlighting variants Datamarking, Delimiting, and Encoding, 0.52, 0.74, and 0.84 respectively. The authors consider that structural format constraints cannot override the backend LLM's semantic understanding of malicious instructions.
- Detection-based defenses: Descriptions generated by QueryIPI have PPL 59.04 and Window PPL 130.98, while the real MCP tool baseline cited in the paper is 1423.27 (PPL) and 1423.31 (Window PPL); the authors state that QueryIPI's perplexity is far lower than this baseline and is robust to statistical anomaly detection.
Other ablations and analyses
- Cross-backend LLM transfer (RQ5, Appendix D, Table 4): Descriptions generated with num=8 are tested on simulated agents with GPT-5, Grok-4, and Gemini-2.5-pro backends; QueryIPI overall average ASR 0.26, TIP 0.10.
- Exceptions and fluctuations: On Cline + GPT-5, QueryIPI reaches 0.95 (TIP is also highest in the same combination, 0.55); after switching backends, Copilot's ASR drops from 0.85 to near 0, which the authors attribute to Copilot's unstructured prompt format that concatenates all tool definitions into one line, and they consider that this format requires model-specific tuning.
- The authors do not report the number of repetitions for the cross-LLM experiments; Table 4 gives only a single ASR value for each combination.
What are some points that can be further explored?
The authors note that the attack depends on prerequisites such as the target system supporting user-defined tools; the experiments cover five simulated and five real agents and four categories of defenses.
Limitations and future directions noted by the authors
- Scope limited to coding agents (Section 7 Limitations): The authors state that query-agnostic attacks as a general paradigm are not inherently limited to the coding domain, but this paper limits scope to coding agents because its threat model assumes the attacker can introduce a custom tool into the victim agent's toolset.
- Depends on architectural preconditions (Section 7): The method requires the target system to support user-defined tools and to incorporate tool descriptions directly into the agent context; the authors state it could in theory extend to any framework meeting these conditions, but this paper does not do so.
- Requires a relatively capable backend LLM (Section 7): The authors state that safety guardrails are a potential obstacle but not a fundamental barrier, and that attackers can use existing jailbreak techniques to bypass alignment filters.
Experimental coverage
- The subjects are five simulated coding agents (Cursor, Copilot, Cline, Trae, Windsurf, with Claude-Sonnet-4 as backend) and the corresponding five real coding agents; cross-backend transfer covers three models, GPT-5, Grok-4, and Gemini-2.5-pro (Table 4).
- The malicious payloads are 10 commands selected from the Command Injection Payload List, and ASR is computed for each configuration using 100 test cases (10 commands × 10 queries).
- Defense evaluations include Sandwich Defense, three Spotlighting variants (Datamarking, Delimiting, Encoding), and PPL/Window PPL detection.
- Judge consistency is computed over 152 data points, reporting an average Spearman's ρ of 0.7790 and Kendall's τ of 0.6975 (Appendix B).
- The paper does not report the specific models of the Mutation LLM and Judge LLM, the number of queries generated for attacks, or the number of repetitions for each experiment.
Summarize the main content of the paper
QueryIPI uses leaked internal prompts to iteratively optimize malicious tool descriptions, achieving query-agnostic IPI on simulated and real coding agents.
A paper on indirect prompt injection attacks against coding agents. The authors note that existing IPI is all query-specific, requiring a specific user query to trigger, and generalizes poorly, so they propose the query-agnostic IPI paradigm: making the malicious payload execute under any user query.
- Core idea: Identify the internal prompt (system instructions and internal tool descriptions) as the coding agent's system invariant, treat the malicious tool description as an optimizable payload, have the Mutation LLM perform initial seed generation and iterative reflection, and have the Judge LLM assign continuous 0–100 scores, conducting a black-box evolutionary search.
- Threat model: The attacker does not know the runtime state but knows the victim agent's version number, can replicate and test locally, and can inject the malicious tool into the tool set through supply chain and other means.
- Main results: On five simulated coding agents backed by Claude-Sonnet-4, QueryIPI achieves average ASR of 70%/82%/87% (num=2/4/8), the best baseline TIP achieves 50%, and AgentDojo, InjecAgent, and MCPTox average no more than 2% (Table 1).
- Internal prompt ablation: Without the internal prompt, average ASR drops to 20%; with a public, related but non-identical Partial Prompt, it is 71% (Table 2); the authors conclude from this that the attacker does not need the exact latest system prompt.
- Transfer and defenses: Descriptions with num=8 transfer to five real coding agents with average ASR 50% (TIP 2%, Table 3); across GPT-5, Grok-4, and Gemini-2.5-pro backends, average ASR is 26% (Table 4); under Sandwich Defense, average ASR remains 0.82, and under Spotlighting variants 0.52–0.84.
- Authors' conclusion: The authors state that query-agnostic IPI is a practical, deterministic threat that exposes the security risk posed by internal prompt leakage; the authors also note that the method depends on the target system supporting user-defined tools and incorporating their descriptions into context, and requires a relatively capable backend LLM.