SafeCodeRL: Security-Constrained Multi-Agent Reinforcement Learning for Trustworthy LLM-Generated IoT/CPS Software
Zhihua Wang, Junfan Chen, Zixiang Wei, Lan Lin, Guoxiang Tong
University of Shanghai for Science and Technology · Beijing University of Technology
Key points
From the paper's conclusion- To address this challenge, we propose SafeCodeRL, a framework that integrates multi-agent collaboration with constrained reinforcement learning for trustworthy LLM-generated IoT/CPS software.
Abstract
Internet of Things (IoT), sensor-network, and cyber-physical system (CPS) software increasingly relies on large language models (LLMs) and autonomous agents for code generation, maintenance, and vulnerability repair. However, LLM-generated edge services, telemetry APIs, configuration handlers, and data-aggregation routines can introduce SQL injection, path traversal, command injection, hard-coded credentials, and unsafe device-control logic, which may compromise sensing data integrity and system safety. Existing approaches largely rely on static post hoc analysis and lack a unified modeling of the generation process, making it difficult to achieve a principled trade-off between functionality and security. To address this challenge, we propose SafeCodeRL, a framework that integrates multi-agent collaboration with constrained reinforcement learning for trustworthy LLM-generated IoT/CPS software. SafeCodeRL models code generation as a security-aware sequential decision process, where Planner, Code, Security, Test, and Critic agents jointly optimize task decomposition, code synthesis, vulnerability auditing, and sandbox-based validation. We design a constraint-aware policy based on Proximal Policy Optimization, augmented with a Lagrangian mechanism and a shielding strategy to explicitly enforce security constraints. Experiments on real-world engineering and security benchmarks, including SWE-bench, SecurityEval, and CyberSecEval, show that SafeCodeRL reduces high-risk vulnerabilities by over 60% while maintaining high functional correctness. A scenario-level IoT/CPS case study further demonstrates that SafeCodeRL substantially improves secure pass rates for sensor telemetry, edge gateway, configuration-management, and data-aggregation tasks, providing a practical path toward trustworthy AI-assisted software development for sensor-driven systems.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- Secure Agentic Coding through Counterexample-Grounded FeedbackarXiv · 2026
- AgentCap: Capability-Based Runtime Authorization for Secure LLM Agent ExecutionarXiv · 2026
- From Instructions to Exploits: Applying Program Analysis to Malicious Agent Skills Across Natural Language and CodearXiv · 2026
- AgentLens: Graph-guided Security Auditing for LLM-based AgentsarXiv · 2026
- Network-Exposed Configuration Attacks on LLM-Controlled Social RobotsarXiv · 2026
- AgentFlow: A Flow-Centric Policy Language and Framework for Securing LLM Agent SystemsarXiv · 2026