mlsanityData to 14 Oct 2026

PurpCode: Reasoning for Safer Code Generation

arXiv 2507.19060 ↗First posted 25 Jul 2025cs.CR cs.CL cs.LGcited by 18

On the map: LLM reasoning → Reasoning for agents, planning and code

Abstract (arXiv)

We introduce PurpCode, the first post-training recipe for training safe code reasoning models towards generating secure code and defending against malicious cyberactivities. PurpCode trains a reasoning model in two stages: (i) Rule Learning, which explicitly teaches the model to reference cybersafety rules to generate vulnerability-free code and to avoid facilitating malicious cyberactivities; and (ii) Reinforcement Learning, which optimizes model safety and preserves model utility through diverse, multi-objective reward mechanisms. To empower the training pipelines with comprehensive cybersafety data, we conduct internal red-teaming to synthesize comprehensive and high-coverage prompts based on real-world tasks for inducing unsafe cyberactivities in the model. Based on PurpCode, we develop a reasoning-based coding model, namely PurpCode-32B, which demonstrates state-of-the-art cybersafety, outperforming various frontier models. Meanwhile, our alignment method decreases the model overrefusal rates in both general and cybersafety-specific scenarios, while preserving model utility in both code generation and common security knowledge.

Key facts. Cited by 18 papers in the map (data through 14 Oct 2026). Placed in Reasoning for agents, planning and code, one of 17 directions in LLM reasoning. Builds on 60 of its 137 references that are in the map. First posted on arXiv 25 Jul 2025.

Builds on

60 of 137 references.

Closest ancestors · 3

Same direction, newest first

  1. 2025KodCode: A Diverse, Challenging, and Verifiable Synthetic Dataset for Coding4 Mar
  2. 2024Deliberative Alignment: Reasoning Enables Safer Language Models20 Dec
  3. 2024Qwen2.5-Coder Technical Report18 Sep

Other references · 57

  1. 2022Training language models to follow instructions with human feedbackcited by 15,971
  2. 2021Evaluating Large Language Models Trained on Codecited by 8,320
  3. 2025DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learningcited by 6,330
  4. 2024Qwen2.5 Technical Reportcited by 4,942
  5. 2025DAPO: An Open-Source LLM Reinforcement Learning System at Scalecited by 2,810
  6. 2023Code Llama: Open Foundation Models for Codecited by 2,139
  7. 2024HybridFlow: A Flexible and Efficient RLHF Frameworkcited by 2,057
  8. 2024HarmBench: A Standardized Evaluation Framework for Automated Red Teaming and Robust Refusalcited by 1,429
  9. 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,391
  10. 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 906
  11. 2022CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesiscited by 885
  12. 2023StarCoder: may the source be with you!cited by 799
38 more
  1. 2023AutoDAN: Generating Stealthy Jailbreak Prompts on Aligned Large Language Modelscited by 785
  2. 2023WizardCoder: Empowering Code Large Language Models with Evol-Instructcited by 733
  3. 2021Deduplicating Training Data Makes Language Models Bettercited by 714
  4. 2025SFT Memorizes, RL Generalizes: A Comparative Study of Foundation Model Post-trainingcited by 672
  5. 2024BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructionscited by 546
  6. 2024JailbreakBench: An Open Robustness Benchmark for Jailbreaking Large Language Modelscited by 536
  7. 2023XSTest: A Test Suite for Identifying Exaggerated Safety Behaviours in Large Language Modelscited by 505
  8. 2025Process Reinforcement through Implicit Rewardscited by 504
  9. 2024StarCoder 2 and The Stack v2: The Next Generationcited by 502
  10. 2024WildGuard: Open One-Stop Moderation Tools for Safety Risks, Jailbreaks, and Refusals of LLMscited by 496
  11. 2023"Do Anything Now": Characterizing and Evaluating In-The-Wild Jailbreak Prompts on Large Language Modelscited by 489
  12. 2024Jailbreaking Leading Safety-Aligned LLMs with Simple Adaptive Attackscited by 486
  13. 2023LMSYS-Chat-1M: A Large-Scale Real-World LLM Conversation Datasetcited by 461
  14. 2025Cognitive Behaviors that Enable Self-Improving Reasoners, or, Four Habits of Highly Effective STaRscited by 377
  15. 2022CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learningcited by 358
  16. 2019Devign: Effective Vulnerability Identification by Learning Comprehensive Program Semantics via Graph Neural Networkscited by 272
  17. 2023Magicoder: Empowering Code Generation with OSS-Instructcited by 256
  18. 2024JailBreakV: A Benchmark for Assessing the Robustness of MultiModal Large Language Models against Jailbreak Attackscited by 230
  19. 2024WildTeaming at Scale: From In-the-Wild Jailbreaks to (Adversarially) Safer Language Modelscited by 223
  20. 2024ArtPrompt: ASCII Art-based Jailbreak Attacks against Aligned LLMscited by 216
  21. 2023OctoPack: Instruction Tuning Code Large Language Modelscited by 189
  22. 2025Constitutional Classifiers: Defending against Universal Jailbreaks across Thousands of Hours of Red Teamingcited by 181
  23. 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 155
  24. 2024Vulnerability Detection with Code Language Models: How Far Are We?cited by 139
  25. 2024OpenCoder: The Open Cookbook for Top-Tier Code Large Language Modelscited by 130
  26. 2025MiMo: Unlocking the Reasoning Potential of Language Model -- From Pretraining to Posttrainingcited by 121
  27. 2023DiverseVul: A New Vulnerable Source Code Dataset for Deep Learning Based Vulnerability Detectioncited by 102
  28. 2024RedCode: Risky Code Execution and Generation Benchmark for Code Agentscited by 90
  29. 2024Instruction Tuning for Secure Code Generationcited by 68
  30. 2024SelfCodeAlign: Self-Alignment for Code Generationcited by 62
  31. 2025CWEval: Outcome-driven Evaluation on Functionality and Security of LLM Code Generationcited by 59
  32. 2024CYBERSECEVAL 3: Advancing the Evaluation of Cybersecurity Risks and Capabilities in Large Language Modelscited by 58
  33. 2023CodeLMSec Benchmark: Systematically Evaluating and Finding Security Vulnerabilities in Black-Box Code Language Modelscited by 55
  34. 2024CyberMetric: A Benchmark Dataset based on Retrieval-Augmented Generation for Evaluating LLMs in Cybersecurity Knowledgecited by 55
  35. 2025Foot-In-The-Door: A Multi-turn Jailbreak for LLMscited by 54
  36. 2024Malla: Demystifying Real-world Large Language Model Integrated Malicious Servicescited by 33
  37. 2024RMCBench: Benchmarking Large Language Models' Resistance to Malicious Codecited by 28
  38. 2025OpenAI's Approach to External Red Teaming for AI Models and Systemscited by 28

50 most cited of 57 All 57 (JSON)

Built on by

Cited by year (2026 to 14 Oct)

Citing papers per year: 2025: 6; 2026: 12.

18 papers.

Sort:

By area:

  1. 2025A Comprehensive Survey on Benchmarks and Solutions in Software Engineering of LLM-Empowered Agentic Systemcited by 15
  2. 2025SecureVibeBench: Benchmarking Secure Vibe Coding of AI Agents via Reconstructing Vulnerability-Introducing Scenarioscited by 13
  3. 2026Controlled Self-Evolution for Algorithmic Code Optimizationcited by 12
  4. 2025CoRe3D: Collaborative Reasoning as a Foundation for 3D Intelligencecited by 10
  5. 2026Secure Code Generation via Online Reinforcement Learning with Vulnerability Reward Modelcited by 6
  6. 2025CTIConnect: A Benchmark for Retrieval-Augmented LLMs over Heterogeneous Cyber Threat Intelligencecited by 4
  7. 2026From SFT to RL: Demystifying the Post-Training Pipeline for LLM-based Vulnerability Detectioncited by 4
  8. 2026Learning to Generate Secure Code via Token-Level Rewardscited by 2
  9. 2025DualGauge: Automated Joint Security-Functionality Benchmarking of Specification-Only Code Generation by LLMs and Coding Agentscited by 1
  10. 2026SecPI: Secure Code Generation with Reasoning Models via Security Reasoning Internalizationcited by 1
  11. 2026Adversarial Arena: Crowdsourcing Data Generation through Interactive Competitioncited by 1
  12. 2026Themis: Training Robust Multilingual Code Reward Models for Flexible Multi-Criteria Scoringcited by 1
6 more
  1. 2025Amazon Nova AI Challenge -- Trusted AI: Advancing secure, AI-assisted software developmentcited by 0
  2. 2026ARuleCon: Agentic Security Rule Conversioncited by 0
  3. 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forwardcited by 0
  4. 2026MiST: Mid-Training LLMs for Cybersecuritycited by 0
  5. 2026SecureVibe: Making Vibe Coding More Securecited by 0
  6. 2026Last Secure Code Benchmark: Is the Code You Vibe Secure?cited by 0

Similar, not cited

Close in wording, no citation either way

  1. 2025R2Vul: Learning to Reason about Software Vulnerabilities with Reinforcement Learning and Structured Reasoning Distillation
  2. 2026RedShell: A Generative AI-Based Approach to Ethical Hacking
  3. 2025RAJ-PGA: Reasoning-Activated Jailbreak and Principle-Guided Alignment Framework for Large Reasoning Models
  4. 2026STAR-S: Improving Safety Alignment through Self-Taught Reasoning on Safety Rules
  5. 2024LLM-Powered Code Vulnerability Repair with Reinforcement Learning and Semantic Reward
  6. 2026Llama-3.1-FoundationAI-SecurityLLM-Reasoning-8B Technical Report
  7. 2025VulInstruct: Teaching LLMs Root-Cause Reasoning for Vulnerability Detection via Security Specifications
  8. 2026Inference-Time Safety For Code LLMs Via Retrieval-Augmented Revision