NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

RedCoder: Automated Multi-Turn Red Teaming for Code LLMs

Wenjie Jacky Mo, Qin Liu, Xiaofei Wen, Dongwon Jung, Hadi Askari, Wenxuan Zhou, Zhe Zhao, Muhao Chen

TL;DR

REDCODER is an automated red-teaming agent designed to expose security vulnerabilities in Code LLMs through multi-turn dialogue. By simulating a "gaming process" between attackers and defenders, it builds a strategy arsenal that allows it to bypass safety filters and induce models into generating insecure code with success rates as high as 65%.

What Problem Does This Paper Address?

As Large Language Models (LLMs) become staples in software engineering—handling everything from unit testing to function implementation—their security is paramount. However, these models are often trained on massive, uncurated codebases that contain "risky patterns."

Current "red teaming" (security stress-testing) methods for these models suffer from two main flaws:

  1. Human-Dependency: They often require extensive manual effort to craft adversarial prompts, making them hard to scale.
  2. Single-Turn Limitation: Most existing attacks focus on a single prompt. In reality, developers interact with AI over multiple turns. An attacker can use this "back-and-forth" to gradually steer a model toward generating a vulnerability that a single-turn safety filter would have caught.

Methods

The authors propose a pipeline to build REDCODER, which operates in three main phases:

  1. Multi-Agent Gaming: To generate training data, the authors set up a simulation where four agents interact:
  2. Attacker: Tries to elicit vulnerable code.
  3. Defender: A Code LLM equipped with a multi-turn guardrail.
  4. Evaluator: Uses static analysis (Amazon CodeGuru) to check if the generated code is actually vulnerable.
  5. Strategy Analyst: This is the "brain" of the operation. It compares failed attack attempts with successful ones to extract high-level "tactics" (e.g., "use subtle inquiries to build trust").
  6. Training: The successful "prototype conversations" from the gaming phase are used to fine-tune a red-team LLM (specifically Llama-3-8B-Instruct). This teaches the model how to steer a conversation toward a security exploit.
  7. Deployment with RAG: When attacking a new victim model, REDCODER uses Retrieval-Augmented Generation (RAG). It looks at the current conversation state, finds a similar situation in its "Strategy Arsenal," and retrieves the tactic that worked previously to guide its next response.

Datasets

The researchers curated a benchmark of 170 coding tasks spanning 43 distinct security vulnerabilities from the Common Weakness Enumeration (CWE) taxonomy (e.g., OS command injection, path traversal).

  • Seed Tasks: Direct requests for vulnerable code.
  • Augmented Tasks: "Reverse-engineered" versions created by GPT-4o to be more naturalistic and implicit, making them harder for guardrails to detect.

Key Insights and Ideas

  • The "Salami Slicing" of Malice: Single-turn guardrails are largely ineffective against multi-turn attacks. An attacker can introduce "benign" components of an exploit across several turns; the cumulative context becomes malicious, but no single turn triggers the alarm.
  • Learning from Failure: The most effective part of the REDCODER pipeline is the Strategy Analyst. By identifying the specific behavioral shift that turned a "refusal" into a "success," the system learns how to bypass alignment filters systematically.
  • Reasoning Doesn't Equal Safety: Interestingly, even reasoning-heavy models like DeepSeek-R1-Distill-8B remained highly vulnerable (40% success rate), suggesting that "thinking" steps don't necessarily help a model recognize when it is being steered toward a security violation.

Key Results

REDCODER significantly outperformed existing state-of-the-art red-teaming methods:

  • High Success Rates: It induced vulnerabilities in 61.18% of cases for CodeGemma-7B and 65.29% for Qwen2.5-Coder-7B.
  • Baseline Comparison: Traditional single-turn attacks like GCG or AutoDAN often struggled to break 15% success on the same models.
  • Guardrail Evasion: Even when the victim models were protected by "ThinkGuard" (a state-of-the-art multi-turn guardrail), REDCODER still maintained a high success rate, proving that current defenses are not yet robust enough for interactive coding scenarios.

Limitations and Future Work

  • Evaluator Accuracy: The study relies on Amazon CodeGuru for automated vulnerability detection. While pragmatic, static analysis tools can have false positives or miss complex, logic-based vulnerabilities.
  • CWE Coverage: While 43 CWE types were covered, the full taxonomy includes over 900. Future work could expand the "Strategy Arsenal" to cover more obscure or domain-specific security flaws.
  • The "Cat-and-Mouse" Game: The authors acknowledge that while REDCODER is a powerful tool for developers to test their models, it could theoretically be used by malicious actors. They emphasize that this research is intended to help build the "context-aware" guardrails necessary to defend against such automated threats.

Summary updated

BibTeX
@inproceedings{mo2026redcoder,
  author = {Wenjie Jacky Mo and Qin Liu and Xiaofei Wen and Dongwon Jung and Hadi Askari and Wenxuan Zhou and Zhe Zhao and Muhao Chen},
  title = {{RedCoder: Automated Multi-Turn Red Teaming for Code LLMs}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.acl-long.1531},
}

Loading related content...

Figure