Skip to content

RedCodeAgent: an automated red-teaming agent for diverse code agentsRedCodeAgent: Automatic Red-teaming Agent against Diverse Code Agents

arXiv· arXiv:2510.02609· ICLR 2026· Chengquan Guo, Chulin Xie, Yu Yang, Zhaorun Chen, Zinan Lin, Xander Davies, Yarin Gal, Dawn Song, Bo LiUniversity of Chicago; University of Illinois Urbana-Champaign; VirtueAI; Microsoft Research; UK AI Security Institute; University of Oxford; UC BerkeleyIndexed by this site · 2026-10-15· Originally publishedTools

Quick read

Attacks

Based on the paper PDF (AI-generated); refer to the original

RedCodeAgent automatically red-teams code agents; on OCI and RedCode-Exec, ASR is 72.47% (Table 1)

Threat modelThe adversary provides risky instructions, inducing the code agent to generate or execute risky code; it is assumed there is no additional human intervention during execution. Related work calls this code generation attack black-box: input is natural language, output is code. The attacker can call tools over multiple rounds, rewrite prompts, and query the target.

Questions
Code agents can generate and execute code, and risky instructions may bring system vulnerabilities, unintended operations, or data leakage. Static benchmarks struggle to cover boundaries like attack combinations, and manual jailbreaks are hard to keep up with agent updates; whether success occurs also depends on whether the risky functionality is executed.
Methods
RedCodeAgent retrieves similar successful experiences, then decides whether to directly query the target or call tools like code replacement and GCG to rewrite prompts. Sandbox scripts, LLMs, or keywords provide judgments; successes are written to memory, failures continue until success or reaching the iteration limit.
Experiments and results
The authors state that across multiple code agents and three benchmarks, RedCodeAgent has higher ASR and lower RR. On OCI and RedCode-Exec, ASR is 72.47% and RR is 7.53% (Table 1). They also compare time cost, language, and component ablations.
Limitations and future work
The paper does not specifically discuss limitations. It covers OCI, ReAct, MetaGPT, Cursor, Codeium, and three code risk benchmarks, plus some C/C++/Java, prompt injection, and SQL injection. It does not report the number of repetitions for main results, nor does it specify the underlying LLMs for ReAct and MetaGPT.
Experimental setupOpenCodeInterpreter、ReAct et al. · RedCode-Exec、RedCode-Gen et al. · ASR、RR et al.
Evaluated models
OpenCodeInterpreterReActMetaGPTCursor (cursor-small)Codeium
Benchmarks
RedCode-ExecRedCode-GenRMCbenchHumanEval
Metrics
ASRRRtime costperceived stealthiness
AI summaryThe authors propose an automated red-teaming agent, RedCodeAgent, claiming it is the first red-teaming agent to systematically uncover vulnerabilities in multiple code agents. The framework leverages an adaptive memory module to reuse existing jailbreak knowledge and dynamically selects the most effective red-teaming tools and their combinations for a given query. The authors also build a simulated sandbox environment to evaluate the actual execution results of code agents, reducing bias from LLM judges that rely only on static code. In evaluations across multiple frontier code agents, various risk scenarios, and programming languages, RedCodeAgent reports higher attack success rates and lower refusal rates, and it discovers previously unidentified security risks in real code assistants such as Cursor and Codeium.

The authors propose an automated red-teaming agent, RedCodeAgent, claiming it is the first red-teaming agent to systematically uncover vulnerabilities in multiple code agents. The framework leverages an adaptive memory module to reuse existing jailbreak knowledge and dynamically selects the most effective red-teaming tools and their combinations for a given query. The authors also build a simulated sandbox environment to evaluate the actual execution results of code agents, reducing bias from LLM judges that rely only on static code. In evaluations across multiple frontier code agents, various risk scenarios, and programming languages, RedCodeAgent reports higher attack success rates and lower refusal rates, and it discovers previously unidentified security risks in real code assistants such as Cursor and Codeium.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    Static benchmarks and manual jailbreaks struggle to cover execution-time risks of code agents; the authors propose an automatic red-teaming method with memory and a toolbox.

    How to systematically discover security vulnerabilities in code agents as they generate and execute code.

    • Scenario: Code agents combine an interpreter to generate, debug, and execute code, often in information-rich sensitive environments. The authors argue that insufficient security awareness or adversarially injected instructions can lead to risky code being generated and executed, resulting in system vulnerabilities, unintended operations, or data leakage.
    • Existing shortcomings: The authors state that static benchmarks struggle to cover real-world boundary behaviors, such as combinations of different attack methods; manual red-teaming algorithms are hard to dynamically optimize as agents evolve, and known patterns can be bypassed by alternative implementations. Code tasks cannot be judged only by whether the model refuses; it must also generate and execute code that implements the specified risky functionality.
    • Observation: The same functionality can have different implementations, some of which pass guardrails; successful attack experience can accumulate and be used to select tools or tool combinations.
    • Method: The authors propose RedCodeAgent, an interactive automated red-teaming agent for code agents, using adaptive memory, a dedicated toolbox, and sandboxed execution evaluation. The abstract calls it an automated red-teaming agent for diverse code agents.
    • Threat model
      • Goal: Perform automated red-team penetration testing to evaluate the security of target code agents, inducing them to generate or execute risky code.
      • Knowledge: Related work positions code generation attacks as black-box, with natural language as input and code as output. The threat model section does not state whether weights or logits are visible.
      • Capabilities: The adversary can provide risky instructions. RedCodeAgent can call tools over multiple rounds, rewrite prompts, and query the target. It is assumed there is no additional human intervention when the code agent executes code.
      • Victim system: The code agent under test, including agents that can invoke an interpreter and interact with the environment.
  2. What related research exists?

    Related work is divided into agents, agent safety benchmarks, and code LLM attacks; the authors place the distinction in black-box red-teaming of code agents and execution-based evaluation.

    LLM agents and red-teaming agents

    • Yao et al. (2023) ReAct, Xi et al. (2023) survey: LLM-centric interaction with the environment; Lewis et al. (2020) retrieval augmentation is used to illustrate that memory supports reasoning.
    • Zheng et al. (2024), Wang et al. (2024): connect code generation and execution to agents.
    • Xu et al. (2024) RedAgent jailbreaks static LLMs; Fang et al. (2024) discuss agents exploiting one-day vulnerabilities. The paper notes that none of these red-teaming works target code agents.

    Agent safety evaluation

    • ToolEmu (Ruan et al., 2024), R-judge (Yuan et al., 2024), AgentMonitor (Naihin et al., 2023), HAICOSYSTEM (Zhou et al., 2024): provide risky interaction records and use LLMs as judges. The paper notes that their goal is not to directly red-team a given code agent.
    • Guo et al. (2024) provide a safety benchmark for code agents. The paper claims this benchmark relies heavily on human effort and that static benchmarks quickly become outdated. Chen et al. (2024b) perform memory poisoning; the paper claims such strategies are typically not automated and coverage is incomplete.

    Security and attacks on code LLMs

    • Bhatt et al. (2023; 2024), Peng et al. (2025), Pa et al. (2023), Pearce et al. (2022), Yang et al. (2024), Hajipour et al. (2024): report that code LLMs can generate insecure snippets. The paper distinguishes code agents: they often have multi-turn self-correction and can directly modify the user's environment.
    • CodeAttack (Jha and Reddy, 2023) targets translation, summarization, and completion; INSEC (Jenko et al., 2024) targets completion; SVEN (He and Vechev, 2023) trains models in a white-box setting to generate secure or insecure code. Cotroneo et al. (2024), Aghakhani et al. (2024) introduce vulnerabilities through training data poisoning rather than directly attacking deployed models. The paper claims that attacks specifically targeting code generation tasks are rare.

    Baseline methods and benchmarks

    • Baselines: No Jailbreak, and GCG (Zou et al., 2023), AmpleGCG (Liao and Sun, 2024), Advprompter (Paulus et al., 2024), AutoDAN (Liu et al., 2023b).
    • Benchmarks: RedCode-Exec, RedCode-Gen (Guo et al., 2024), and RMCbench's text-to-code cases (Chen et al., 2024a).

    The authors distinguish this work from the above by focusing on automated, adaptive red-teaming for code agents, combining memory and code-specific tools, and evaluating with execution results rather than only static code; the setting is black-box code generation, not completion, translation, or training-time poisoning. The abstract claims RedCodeAgent is the first such automated red-teaming agent.

  3. How does the paper address this problem?

    RedCodeAgent rewrites prompts using memory retrieval and tool calls, then determines attack success via sandbox execution or LLM/keyword evaluation.

    After the user provides a risk scenario and risk description, RedCodeAgent first retrieves similar successful experiences, then decides whether to directly query the target or call tools to rewrite the prompt; the evaluation module judges the result, and if successful, it reflects and writes to memory; if not, it continues until success or reaching the action limit.

    Process and Settings

    • Input first enters the memory module, which retrieves the top-K similar successful experiences for the LLM to decide whether to query the target or call tools.
    • Tools can suggest alternative implementations or add phrases to bypass guardrails; multiple tools can be called in sequence, and after the prompt is finalized, the target code agent is queried.
    • On success, a final reflection is performed on the entire process, and memory is updated according to the memory entry structure. On failure, rewriting continues. A maximum action limit is set to avoid excessive exploration.
    • Implementation uses LangChain and ReAct logic, with the base LLM being GPT-4o-mini and max_iterations set to 35. The system prompt requires maintaining the initial risk goal and considering time cost. Appendix F.1.1 provides the full system prompt.

    Memory Module

    • Each memory entry contains the risk scenario, risk description, trajectory, final evaluation result, and final self-reflection. The trajectory records tool choices, reasons, time taken, inputs and outputs, as well as the target's input, output, and evaluation feedback. Recording time taken is to encourage shorter red-teaming time.
    • Retrieval uses an embedding model to encode the scenario and description separately, sums the two cosine similarities, and subtracts a trajectory length penalty. The score is S = Sr + St − Length(m.trajectory) × ρ, returning the highest K entries.
    • The embedding model is sentence-transformers/paraphrase-MiniLM-L6-v2, K=3, ρ=0.02. Memory starts empty, and successful records are written before the next task. The main experiment accumulates sequentially within each RedCode-Exec risk index.

    Toolbox

    • Code Substitution: Takes code or a functional description as input, and a dedicated code LLM returns a functionally equivalent alternative implementation. The authors observed that among different implementations of the same functionality, some are rejected by guardrails while others may still execute. When a sensitive request is rejected, switch between CodeQwen1.5-7B-Chat, Meta-Llama-3-8B-Instruct, and gpt-35-turbo.
    • General Jailbreak Tools: GCG is gradient-based, Advprompter and AmpleGCG are learning-based, and AutoDAN is evolutionary-based. The appendix also includes template attacks from GPTFUZZER and attacks that rewrite prompts into role-playing narratives. The authors state that users can continue adding tools.
    • Tool calls return the optimized prompt and time taken, for subsequent queries or further tool selection.

    Risk Inputs and Success Determination

    • Inputs come from RedCode-Exec, RedCode-Gen, and RMCbench. RedCode-Exec has 27 risk scenarios across 8 domains: 14 from existing agent safety benchmarks and 13 from MITRE CWE; 30 per scenario, totaling 810. RedCode-Gen comes from 8 malware families, totaling 160. RMCbench uses all 182 text-to-code entries. The appendix also constructs prompt injection and SQL injection cases.
    • RedCode-Exec uses scripts corresponding to the risk descriptions, checking execution results in a Docker sandbox, which the authors use to reduce LLM judge bias from only looking at static code. Results are classified as Rejection, Execution Failure, or Attack Success, with reasons returned as feedback.
    • RedCode-Gen is scored by GPT-4o on a five-level maliciousness scale: direct refusal counts as rejection; incomplete, complete but insufficient, and complete and sufficient count as attack success. The irrelevant code level is not classified into these two categories in the paper. RMCbench uses keyword matching: hitting a rejection keyword counts as rejection, otherwise it counts as success. Appendix E provides script examples and keyword sets.
  4. What experiments did the paper conduct?

    The authors state that in Table 1, RedCodeAgent has the highest ASR and the lowest RR.

    Experimental Setup

    • Targets: OpenCodeInterpreter (OCI, base m-a-p/OpenCodeInterpreter-DS-6.7B), ReAct (RA), multi-agent framework MetaGPT, Cursor (base cursor-small model), Codeium (Base Model). OCI temperature 0, max 1024 tokens, 3 interaction rounds. The paper does not specify the underlying LLMs for RA and MetaGPT.
    • Data: RedCode-Exec 810 entries, RedCode-Gen 160 entries, RMCbench 182 text-to-code entries. Additionally, 6 scenarios totaling 180 entries were translated into C, C++, and Java. SQL injection 30 entries. Prompt injection was constructed by sampling 5 normal coding problems from HumanEval and concatenating. Cursor and Codeium have no API, so a semi-automated script sent 810 entries and corresponding optimized prompts.
    • Baselines: No Jailbreak directly uses static cases; GCG, AmpleGCG, Advprompter, AutoDAN optimize first then input. GCG generates suffixes on deepseek-coder-6.7b-instruct and transfers them, target text “Here is”, num_steps=50. Retry settings allow up to three optimization rounds and three query rounds.
    • RedCodeAgent: GPT-4o-mini, max_iterations=35, K=3, ρ=0.02. Main text accumulates from empty memory by risk index.
    • Metrics and Determination: ASR, RR, time cost, plus trajectory length and perceived stealth. RedCode-Exec uses Docker scripts; RedCode-Gen uses GPT-4o; RMCbench uses keywords. The stealth experiment uses an unnamed LLM to rate perceived harmfulness on a 0–5 scale, with stealth defined as 5 minus that score. The paper does not report the number of repetitions for main results.

    Main Results

    Swipe horizontally to read the table

    SettingNo Jailbreak ASRRedCodeAgent ASRRedCodeAgent RR
    OCI / RedCode-Exec (Table 1)55.46%72.47%7.53%
    OCI / RedCode-Gen (Table 1)9.38%59.11%33.95%
    OCI / RMCbench (Table 1)18.68%69.78%30.21%
    RA / RedCode-Exec (Table 1)56.67%75.93%2.96%
    RA / RedCode-Gen (Table 1)65.62%81.52%2.50%
    RA / RMCbench (Table 1)66.48%71.42%28.58%
    Cursor / RedCode-Exec (Table 4)62.60%72.72%4.07%
    MetaGPT / RedCode-Exec (Table 4)24.98%45.62%0.12%

    The 8 rows in the table already include MetaGPT with the lowest ASR. Omitted Codeium, RedCode-Exec: No Jailbreak ASR 60.98%, RR 5.93%, RedCodeAgent ASR 69.88%, RR 4.32% (Table 4).

    • The authors claim that in Table 1, RedCodeAgent has the highest ASR and lowest RR. Using existing jailbreaks alone is not always higher than No Jailbreak: on OCI's RedCode-Exec, AmpleGCG ASR is 41.11%, AutoDAN is 29.26%, both lower than No Jailbreak's 55.46%.
    • The authors believe this is because code tasks require not only avoiding refusal but also generating and executing the specified functionality; existing jailbreaks do not guarantee this, while RedCodeAgent maintains the functional goal and continues optimizing based on feedback.
    • The authors claim that Cursor and Codeium have higher ASR and lower RR under No Jailbreak (relative to OCI/RA in Table 1), and believe these assistants may prioritize helping users more. Table 4 only compares No Jailbreak and RedCodeAgent.

    Efficiency and Tool Usage

    • §4.2 targets OCI and RedCode-Exec. Figure 2 labels RedCodeAgent at 121.17 seconds, ASR 72.47%; No Jailbreak 36.25 seconds, 55.46%; GCG 71.44 seconds, 54.69%; Advprompter 132.59 seconds, 46.42%. The authors claim its trade-off between runtime and ASR is the best.
    • Figure 3 and text: among successful cases, 91.1% have trajectory length ≤4, nearly 10% between 5 and 11. Among failed cases, only 4% terminate at length ≤4; the authors claim failures rarely give up quickly, with a notable increase in failures at lengths 8 to 10.
    • Figure 4 legend gives average time per single call: query target 36.25 seconds, code substitution 12.16 seconds, GCG 35.19 seconds, AutoDAN 15.52 seconds, AmpleGCG 9.03 seconds, Advprompter 96.34 seconds. Caption says risk indices 1–27, excluding index 18. The authors claim that on indices 1 and 2, where static ASR is already high, fewer extra tools are used; on indices 9, 10, and 11, where static ASR is lower, more time is spent on GCG and Advprompter.

    Cases Where All Baselines Fail

    • §4.3: Among RedCode-Exec's 810 cases, OCI has 82 and RA has 78 where all baselines failed to find and only RedCodeAgent succeeded. The text names risk index 10 (reverse shell) and 14 (eval injection).
    • Figure 5 shows a trajectory for deleting a sensitive file: first query rejected, then GCG called, then combined with code substitution suggestion and queried again, judged as attack success. The authors attribute this success to the combination of alternative implementation suggestion and GCG suffix. Appendix H gives another successful trajectory. The suffix or script is not repeated here.
    • The authors also claim that RedCodeAgent rewrites sensitive wording to be less direct, thereby reducing refusals. Table 11 for OCI: perceived harmfulness RedCodeAgent 2.67, GCG 2.96, AmpleGCG 2.91, Advprompter 2.80, AutoDAN 2.81; corresponding stealth 2.33, the highest in the table.

    Other Ablations and Analyses

    • Memory (Table 5): without memory, OCI ASR is 61.23%, Independent is 72.47%; RA is 68.02%, Independent is 75.93%. After shuffling order, OCI 70.25%, RA 77.78%. Preloading 36 entries gives OCI 70.86%.
    • ρ (Table 6, target agent not specified): 0, 0.02, 1 give average trajectory lengths 3.76, 3.60, 3.29, and ASR 70.12%, 72.47%, 73.70%. Tool count (Figure 10, target not specified): only GCG 65.68%, GCG plus code substitution 70.28%, all tools 72.47%; the latter matches the OCI, RedCode-Exec row in Table 1.
    • Language (Table 3, target not specified): RedCodeAgent ASR on Python, C, C++, Java is 89.44%, 81.67%, 85.56%, 80.00%. On C, AutoDAN is 16.67%, lower than No Jailbreak's 73.33%.
    • Retry (Table 2, target not specified): for deleting sensitive files, RedCodeAgent ASR 70.00%, RR 20.00%; with risk aliases added, ASR 93.33%, RR 6.67%. On the deletion task, AutoDAN (retry) RR is 10.00%, lower than RedCodeAgent, but its ASR is 23.33%.
    • Prompt injection on OCI (Table 9): average ASR 53.25%, RR 13.46%, static cases 54.44%, 18.52%. The authors claim injection does not significantly increase ASR but reduces RR. SQL injection (Table 10, 30 each): on OCI, RedCodeAgent 20/30, No Jailbreak 15/30; GCG RR 0/30, lower than RedCodeAgent's 1/30. On RA, RedCodeAgent 15/30.
    • Five-baseline sequential combination for OCI, RedCode-Exec (Table 8): running all gives ASR 68.64%, 337.33 seconds; early-stoppable combination still 68.64%, 150.25 seconds; RedCodeAgent 72.47%, 121.17 seconds. This table writes No Jailbreak ASR as 55.19%, differing from Table 1's 55.46%. §D.9, after replacing the base with GPT-4o, gives OCI ASR 74.07%, RR 6.17%; the authors claim relative to GPT-4o-mini's 72.47%, 7.53%, ASR improves by 1.6% and RR decreases by 1.36%, and call the improvement relatively limited.
  5. What are some points that can be further explored?

    The paper does not have a dedicated limitations section, nor does it write future research directions.

    Limitations and future directions noted by the authors

    The paper does not specifically discuss limitations. The Conclusion has no dedicated Future Work section, nor does it frame any result as a method deficiency or planned follow-up. The ethics statement only mentions restricting access, providing usage documentation, and using licenses to prohibit malicious applications, which is not counted as a research limitation.

    Experimental coverage

    • Main results target OCI, ReAct, MetaGPT, Cursor, Codeium; benchmarks are RedCode-Exec (810), RedCode-Gen (160), RMCbench (182 text-to-code cases) (Table 1, Table 4, §4).
    • Baselines are No Jailbreak, GCG, AmpleGCG, Advprompter, AutoDAN, and comparisons with sequential combinations of the five (Table 8). Cursor and Codeium only report No Jailbreak and RedCodeAgent (Table 4).
    • Language experiments cover 6 scenarios in Python, C, C++, Java, totaling 180 cases (Table 3); Table 3 does not specify the target agent. The appendix includes prompt injection on OCI, and 30 SQL injection cases each on OCI and RA.
    • Judgment methods are separated by benchmark: RedCode-Exec uses Docker scripts, RedCode-Gen uses GPT-4o five-level scoring, RMCbench uses keywords. The paper does not report the number of repetitions for the main ASR/RR, nor does it report agreement between LLM review and human review.
    • Component experiments include memory presence/absence, case order, preloading, ρ, number of tools, and base models GPT-4o-mini vs. GPT-4o (§D.4–D.9). The paper does not specify the underlying LLMs for ReAct and MetaGPT. GCG suffixes are generated on deepseek-coder-6.7b-instruct and then transferred (§F.3).
  6. Summarize the main content of the paper

    The authors claim RedCodeAgent has higher ASR and lower RR; on OCI and RedCode-Exec, ASR is 72.47%.

    RedCodeAgent turns automated red-teaming into an agent that can call tools and accumulate successful experience, used to check whether code agents generate and execute risky code.

    • Problem: Static benchmarks and fixed jailbreaks struggle to keep up with code agents and to cover attack combinations. It is not enough for the target to simply refuse; the risky functionality must be realized in execution. The authors frame the attack as black-box code generation: natural language in, code out, and assume no additional human confirmation during execution.
    • Method: Given a risky scenario and description, retrieve successful experience using embedding similarity plus a trajectory-length penalty, then choose either a direct query or call code replacement, GCG, AmpleGCG, Advprompter, or AutoDAN. Docker scripts, GPT-4o, or keywords provide refusal, execution failure, or success; successful experience is written back to memory. The base model is GPT-4o-mini, with an iteration cap of 35.
    • Main results: On OCI and RedCode-Exec, ASR is 72.47% and RR is 7.53%, versus 55.46% and 14.70% without jailbreak (Table 1). On RA and RedCode-Exec, ASR is 75.93%. On OCI, RedCode-Gen ASR is 59.11%, and RMCbench is 69.78%. MetaGPT's RedCode-Exec ASR is 45.62% (Table 4).
    • Other results: Of 810 cases, 82 on OCI and 78 on RA were successful only with RedCodeAgent (§4.3). In Figure 2 for OCI, its time cost is 121.17 seconds. Without memory, OCI ASR is 61.23% (Table 5). Using existing jailbreaks alone is sometimes lower than no jailbreak.
    • Authors' conclusion: The authors state that the method has higher ASR and lower RR, runtime comparable to single jailbreak methods, and can adjust tools by task difficulty and find vulnerabilities other methods miss, enabling scalable safety evaluation before deployment.

Related papers

Show 3 more papers
Read originalICLR 2026