# LLM-to-Code Injection

> Master the mechanics of LLM-to-Code Injection. Learn how attackers trick AI into generating malicious code and defend with AST validation and strict sandboxing.

Canonical: https://codelivly.com/rooms/llm-to-code-injection
Last updated: 2026-10-12

| | |
|---|---|
| Level | Intermediate |
| Category | Cybersecurity |
| Lessons | 3 |
| Estimated time | 30 min |
| XP | 100 |

This module explores LLM-to-Code Injection, a critical subset of Insecure Output Handling where applications execute code generated by Large Language Models. You will learn how attackers exploit code interpreters and dynamic execution environments to achieve Remote Code Execution (RCE) or data exfiltration, and how to implement robust defenses like AST validation, strict library allowlisting, and ephemeral sandboxing.

## Lessons

1. What Happens When LLM Output is Executed as Code (30 min)
2. Crafting Prompts That Produce Malicious Code Output (30 min)
3. Guided Lab: Getting a Vulnerable App to Execute LLM-Generated Code (30 min)

## Related

- [Learning path: Insecure Output Handling and Downstream Attacks](https://codelivly.com/learning-paths/insecure-output-handling-downstream-attacks)
- [All rooms](https://codelivly.com/rooms)
