[Paper Review] AutoSafeCoder: A Multi-Agent Framework for Securing LLM Code Generation through Static Analysis and Fuzz Testing
AutoSafeCoder is a multi-agent framework that enhances LLM-generated code security by integrating a Coding Agent, a Static Analyzer Agent, and a Fuzzing Agent using GPT-4o for iterative code generation, vulnerability detection, and dynamic testing. It reduces code vulnerabilities by 13% compared to baseline LLMs while maintaining high functionality, demonstrating the effectiveness of combining static and dynamic analysis in a collaborative LLM-driven pipeline.
Recent advancements in automatic code generation using large language models (LLMs) have brought us closer to fully automated secure software development. However, existing approaches often rely on a single agent for code generation, which struggles to produce secure, vulnerability-free code. Traditional program synthesis with LLMs has primarily focused on functional correctness, often neglecting critical dynamic security implications that happen during runtime. To address these challenges, we propose AutoSafeCoder, a multi-agent framework that leverages LLM-driven agents for code generation, vulnerability analysis, and security enhancement through continuous collaboration. The framework consists of three agents: a Coding Agent responsible for code generation, a Static Analyzer Agent identifying vulnerabilities, and a Fuzzing Agent performing dynamic testing using a mutation-based fuzzing approach to detect runtime errors. Our contribution focuses on ensuring the safety of multi-agent code generation by integrating dynamic and static testing in an iterative process during code generation by LLM that improves security. Experiments using the SecurityEval dataset demonstrate a 13% reduction in code vulnerabilities compared to baseline LLMs, with no compromise in functionality.
Motivation & Objective
- To address the growing risk of security vulnerabilities in LLM-generated code, which often exceeds 40% in existing models.
- To overcome the limitations of single-agent LLM code generation that prioritizes functionality over runtime security.
- To develop a collaborative multi-agent system that integrates static analysis and mutation-based fuzzing for real-time vulnerability detection and repair.
- To maintain high functional correctness while significantly improving code security in automated code generation.
- To provide a scalable, LLM-powered framework that enhances trust in AI-assisted software development.
Proposed method
- The framework employs three specialized LLM-driven agents: a Coding Agent for code generation, a Static Analyzer Agent using Bandit to detect vulnerabilities via AST-based analysis, and a Fuzzing Agent employing mutation-based fuzzing to detect runtime errors.
- Feedback loops are established where the Static Analyzer and Fuzzing Agents iteratively refine the code generated by the Coding Agent based on detected issues.
- Few-shot and in-context learning techniques are applied to enable agents to understand and respond to security patterns and feedback effectively.
- The system uses GPT-4o as the underlying LLM for all agents, with input prompts designed to guide role-specific behavior and improve accuracy.
- Dynamic testing is performed using a custom fuzzer that mutates inputs to trigger edge-case failures, with crash reports used to guide code repair.
- Functionality is validated using the HumanEval benchmark, and security is measured using the SecurityEval dataset and Bandit tool.

Experimental results
Research questions
- RQ1Can a multi-agent LLM framework reduce the number of vulnerabilities in LLM-generated code compared to single-agent baselines?
- RQ2To what extent can static and dynamic analysis agents collaboratively improve code security without degrading functional correctness?
- RQ3How effective is the integration of mutation-based fuzzing with LLM-driven static analysis in detecting runtime vulnerabilities?
- RQ4What is the impact of iterative feedback from analysis agents on the number of vulnerabilities and code repair success rate?
- RQ5Can the framework maintain high functional performance while significantly reducing security flaws in generated code?
Key findings
- AutoSafeCoder reduced the number of vulnerable code samples from 59 out of 121 (49%) with GPT-4o to 44 out of 121 (36%), representing a 13% reduction in vulnerabilities.
- The Static Analyzer Agent successfully fixed 53% of vulnerable code samples within 1 to 4 iterations, with 19% requiring no iterations and 31% remaining unfixed after feedback.
- The Fuzzing Agent processed 65 code samples, successfully detecting and fixing 5 crashes (4% of total samples), with 60 running without crashes.
- Functionality was preserved with a Pass@1 score of 0.8780 for AutoSafeCoder, compared to 0.9085 for GPT-4o, indicating only a 3% decrease in functional correctness.
- CWE-94 was the most frequent vulnerability detected in 25 of the 44 remaining vulnerable samples, highlighting a key target for future LLM fine-tuning.
- The system demonstrated that combining static and dynamic analysis in a multi-agent loop significantly improves security outcomes without sacrificing code usability.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.