PurpCode: Reasoning for Safer Code Generation
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
- 2025KodCode: A Diverse, Challenging, and Verifiable Synthetic Dataset for Coding4 Mar
- 2024Deliberative Alignment: Reasoning Enables Safer Language Models20 Dec
- 2024Qwen2.5-Coder Technical Report18 Sep
Other references · 57
- 2022Training language models to follow instructions with human feedbackcited by 15,971
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2025DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learningcited by 6,330
- 2024Qwen2.5 Technical Reportcited by 4,942
- 2025DAPO: An Open-Source LLM Reinforcement Learning System at Scalecited by 2,810
- 2023Code Llama: Open Foundation Models for Codecited by 2,139
- 2024HybridFlow: A Flexible and Efficient RLHF Frameworkcited by 2,057
- 2024HarmBench: A Standardized Evaluation Framework for Automated Red Teaming and Robust Refusalcited by 1,429
- 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,391
- 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 906
- 2022CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesiscited by 885
- 2023StarCoder: may the source be with you!cited by 799
38 more
- 2023AutoDAN: Generating Stealthy Jailbreak Prompts on Aligned Large Language Modelscited by 785
- 2023WizardCoder: Empowering Code Large Language Models with Evol-Instructcited by 733
- 2021Deduplicating Training Data Makes Language Models Bettercited by 714
- 2025SFT Memorizes, RL Generalizes: A Comparative Study of Foundation Model Post-trainingcited by 672
- 2024BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructionscited by 546
- 2024JailbreakBench: An Open Robustness Benchmark for Jailbreaking Large Language Modelscited by 536
- 2023XSTest: A Test Suite for Identifying Exaggerated Safety Behaviours in Large Language Modelscited by 505
- 2025Process Reinforcement through Implicit Rewardscited by 504
- 2024StarCoder 2 and The Stack v2: The Next Generationcited by 502
- 2024WildGuard: Open One-Stop Moderation Tools for Safety Risks, Jailbreaks, and Refusals of LLMscited by 496
- 2023"Do Anything Now": Characterizing and Evaluating In-The-Wild Jailbreak Prompts on Large Language Modelscited by 489
- 2024Jailbreaking Leading Safety-Aligned LLMs with Simple Adaptive Attackscited by 486
- 2023LMSYS-Chat-1M: A Large-Scale Real-World LLM Conversation Datasetcited by 461
- 2025Cognitive Behaviors that Enable Self-Improving Reasoners, or, Four Habits of Highly Effective STaRscited by 377
- 2022CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learningcited by 358
- 2019Devign: Effective Vulnerability Identification by Learning Comprehensive Program Semantics via Graph Neural Networkscited by 272
- 2023Magicoder: Empowering Code Generation with OSS-Instructcited by 256
- 2024JailBreakV: A Benchmark for Assessing the Robustness of MultiModal Large Language Models against Jailbreak Attackscited by 230
- 2024WildTeaming at Scale: From In-the-Wild Jailbreaks to (Adversarially) Safer Language Modelscited by 223
- 2024ArtPrompt: ASCII Art-based Jailbreak Attacks against Aligned LLMscited by 216
- 2023OctoPack: Instruction Tuning Code Large Language Modelscited by 189
- 2025Constitutional Classifiers: Defending against Universal Jailbreaks across Thousands of Hours of Red Teamingcited by 181
- 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 155
- 2024Vulnerability Detection with Code Language Models: How Far Are We?cited by 139
- 2024OpenCoder: The Open Cookbook for Top-Tier Code Large Language Modelscited by 130
- 2025MiMo: Unlocking the Reasoning Potential of Language Model -- From Pretraining to Posttrainingcited by 121
- 2023DiverseVul: A New Vulnerable Source Code Dataset for Deep Learning Based Vulnerability Detectioncited by 102
- 2024RedCode: Risky Code Execution and Generation Benchmark for Code Agentscited by 90
- 2024Instruction Tuning for Secure Code Generationcited by 68
- 2024SelfCodeAlign: Self-Alignment for Code Generationcited by 62
- 2025CWEval: Outcome-driven Evaluation on Functionality and Security of LLM Code Generationcited by 59
- 2024CYBERSECEVAL 3: Advancing the Evaluation of Cybersecurity Risks and Capabilities in Large Language Modelscited by 58
- 2023CodeLMSec Benchmark: Systematically Evaluating and Finding Security Vulnerabilities in Black-Box Code Language Modelscited by 55
- 2024CyberMetric: A Benchmark Dataset based on Retrieval-Augmented Generation for Evaluating LLMs in Cybersecurity Knowledgecited by 55
- 2025Foot-In-The-Door: A Multi-turn Jailbreak for LLMscited by 54
- 2024Malla: Demystifying Real-world Large Language Model Integrated Malicious Servicescited by 33
- 2024RMCBench: Benchmarking Large Language Models' Resistance to Malicious Codecited by 28
- 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
Citing papers per year: 2025: 6; 2026: 12.
18 papers.
Sort:
By area:
- 2025A Comprehensive Survey on Benchmarks and Solutions in Software Engineering of LLM-Empowered Agentic Systemcited by 15
- 2025SecureVibeBench: Benchmarking Secure Vibe Coding of AI Agents via Reconstructing Vulnerability-Introducing Scenarioscited by 13
- 2026Controlled Self-Evolution for Algorithmic Code Optimizationcited by 12
- 2025CoRe3D: Collaborative Reasoning as a Foundation for 3D Intelligencecited by 10
- 2026Secure Code Generation via Online Reinforcement Learning with Vulnerability Reward Modelcited by 6
- 2025CTIConnect: A Benchmark for Retrieval-Augmented LLMs over Heterogeneous Cyber Threat Intelligencecited by 4
- 2026From SFT to RL: Demystifying the Post-Training Pipeline for LLM-based Vulnerability Detectioncited by 4
- 2026Learning to Generate Secure Code via Token-Level Rewardscited by 2
- 2025DualGauge: Automated Joint Security-Functionality Benchmarking of Specification-Only Code Generation by LLMs and Coding Agentscited by 1
- 2026SecPI: Secure Code Generation with Reasoning Models via Security Reasoning Internalizationcited by 1
- 2026Adversarial Arena: Crowdsourcing Data Generation through Interactive Competitioncited by 1
- 2026Themis: Training Robust Multilingual Code Reward Models for Flexible Multi-Criteria Scoringcited by 1
6 more
- 2025Amazon Nova AI Challenge -- Trusted AI: Advancing secure, AI-assisted software developmentcited by 0
- 2026ARuleCon: Agentic Security Rule Conversioncited by 0
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forwardcited by 0
- 2026MiST: Mid-Training LLMs for Cybersecuritycited by 0
- 2026SecureVibe: Making Vibe Coding More Securecited by 0
- 2026Last Secure Code Benchmark: Is the Code You Vibe Secure?cited by 0
- 2026Last Secure Code Benchmark: Is the Code You Vibe Secure?10 Oct 2026
- 2026SecureVibe: Making Vibe Coding More Secure29 Sep 2026
- 2026MiST: Mid-Training LLMs for Cybersecurity16 Sep 2026
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forward23 Jun 2026
- 2026Themis: Training Robust Multilingual Code Reward Models for Flexible Multi-Criteria Scoring1 May 2026
- 2026Adversarial Arena: Crowdsourcing Data Generation through Interactive Competition20 Apr 2026
- 2026ARuleCon: Agentic Security Rule Conversion8 Apr 2026
- 2026SecPI: Secure Code Generation with Reasoning Models via Security Reasoning Internalization4 Apr 2026
- 2026Learning to Generate Secure Code via Token-Level Rewards26 Feb 2026
- 2026From SFT to RL: Demystifying the Post-Training Pipeline for LLM-based Vulnerability Detection15 Feb 2026
- 2026Secure Code Generation via Online Reinforcement Learning with Vulnerability Reward Model7 Feb 2026
- 2026Controlled Self-Evolution for Algorithmic Code Optimization12 Jan 2026
6 more
- 2025CoRe3D: Collaborative Reasoning as a Foundation for 3D Intelligence14 Dec 2025
- 2025DualGauge: Automated Joint Security-Functionality Benchmarking of Specification-Only Code Generation by LLMs and Coding Agents24 Nov 2025
- 2025CTIConnect: A Benchmark for Retrieval-Augmented LLMs over Heterogeneous Cyber Threat Intelligence13 Oct 2025
- 2025A Comprehensive Survey on Benchmarks and Solutions in Software Engineering of LLM-Empowered Agentic System10 Oct 2025
- 2025SecureVibeBench: Benchmarking Secure Vibe Coding of AI Agents via Reconstructing Vulnerability-Introducing Scenarios26 Sep 2025
- 2025Amazon Nova AI Challenge -- Trusted AI: Advancing secure, AI-assisted software development13 Aug 2025
- 2025A Comprehensive Survey on Benchmarks and Solutions in Software Engineering of LLM-Empowered Agentic Systemcited by 15
- 2025SecureVibeBench: Benchmarking Secure Vibe Coding of AI Agents via Reconstructing Vulnerability-Introducing Scenarioscited by 13
- 2025DualGauge: Automated Joint Security-Functionality Benchmarking of Specification-Only Code Generation by LLMs and Coding Agentscited by 1
- 2026ARuleCon: Agentic Security Rule Conversioncited by 0
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forwardcited by 0
- 2026Last Secure Code Benchmark: Is the Code You Vibe Secure?cited by 0
- 2026Last Secure Code Benchmark: Is the Code You Vibe Secure?10 Oct 2026
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forward23 Jun 2026
- 2026ARuleCon: Agentic Security Rule Conversion8 Apr 2026
- 2025DualGauge: Automated Joint Security-Functionality Benchmarking of Specification-Only Code Generation by LLMs and Coding Agents24 Nov 2025
- 2025A Comprehensive Survey on Benchmarks and Solutions in Software Engineering of LLM-Empowered Agentic System10 Oct 2025
- 2025SecureVibeBench: Benchmarking Secure Vibe Coding of AI Agents via Reconstructing Vulnerability-Introducing Scenarios26 Sep 2025
- 2026Controlled Self-Evolution for Algorithmic Code Optimizationcited by 12
- 2026Learning to Generate Secure Code via Token-Level Rewardscited by 2
- 2026Adversarial Arena: Crowdsourcing Data Generation through Interactive Competitioncited by 1
- 2025Amazon Nova AI Challenge -- Trusted AI: Advancing secure, AI-assisted software developmentcited by 0
- 2026MiST: Mid-Training LLMs for Cybersecuritycited by 0
- 2026SecureVibe: Making Vibe Coding More Securecited by 0
- 2026SecureVibe: Making Vibe Coding More Secure29 Sep 2026
- 2026MiST: Mid-Training LLMs for Cybersecurity16 Sep 2026
- 2026Adversarial Arena: Crowdsourcing Data Generation through Interactive Competition20 Apr 2026
- 2026Learning to Generate Secure Code via Token-Level Rewards26 Feb 2026
- 2026Controlled Self-Evolution for Algorithmic Code Optimization12 Jan 2026
- 2025Amazon Nova AI Challenge -- Trusted AI: Advancing secure, AI-assisted software development13 Aug 2025
Similar, not cited
Close in wording, no citation either way
- 2025R2Vul: Learning to Reason about Software Vulnerabilities with Reinforcement Learning and Structured Reasoning Distillation
- 2026RedShell: A Generative AI-Based Approach to Ethical Hacking
- 2025RAJ-PGA: Reasoning-Activated Jailbreak and Principle-Guided Alignment Framework for Large Reasoning Models
- 2026STAR-S: Improving Safety Alignment through Self-Taught Reasoning on Safety Rules
- 2024LLM-Powered Code Vulnerability Repair with Reinforcement Learning and Semantic Reward
- 2026Llama-3.1-FoundationAI-SecurityLLM-Reasoning-8B Technical Report
- 2025VulInstruct: Teaching LLMs Root-Cause Reasoning for Vulnerability Detection via Security Specifications
- 2026Inference-Time Safety For Code LLMs Via Retrieval-Augmented Revision