Skip to main content

Self-Execution Simulation Improves Coding Models

AuthorsGallil Maimon et al.
Year2026
HF Upvotes33
arXiv2604.03253
PDFDownload
HF PageView on Hugging Face

Abstract

A promising research direction in enabling LLMs to generate consistently correct code involves addressing their inability to properly estimate program execution, particularly for code they generate. In this work, we demonstrate that Code LLMs can be trained to simulate program execution in a step-by-step manner and that this capability can be leveraged to improve competitive programming performance. Our approach combines supervised fine-tuning on natural language execution traces, textual explanations grounded in true execution, with reinforcement learning using verifiable rewards. We introduce two complementary objectives: output prediction given code and inputs, and solving competitive programming tasks with either ground-truth or self-predicted execution feedback. These objectives enable models to perform self-verification over multiple candidate solutions, and iterative self-fixing by simulating test execution. Across multiple competitive programming benchmarks, our method yields consistent improvements over standard reasoning approaches. We further present ablations and analysis to elucidate the role of execution simulation and its limitations.


Engineering Breakdown

Plain English

This paper addresses a fundamental weakness in code-generating language models: they cannot reliably simulate program execution to verify their own outputs. The authors train code LLMs to predict step-by-step execution traces using supervised fine-tuning on natural language explanations of how code runs, then combine this with reinforcement learning using verifiable rewards from actual execution. By teaching models to simulate execution and use that feedback to improve their own code generation, they achieve better performance on competitive programming tasks compared to baseline approaches that lack this execution awareness.

Core Technical Contribution

The core innovation is a dual-objective training framework that explicitly teaches code LLMs to simulate program execution as an intermediate capability, then leverages simulated execution as feedback for improving code generation. Unlike prior work that treats execution verification as purely external validation, this approach makes execution simulation a learnable skill that becomes part of the model's reasoning process. The paper introduces two complementary training objectives—predicting outputs given code and inputs, and solving programming tasks with either ground-truth or self-predicted execution feedback—that enable the model to ground its code generation in executable reasoning rather than surface-level pattern matching.

How It Works

The training pipeline starts with supervised fine-tuning on execution traces: the model learns to predict what a code snippet will output given specific inputs, using natural language step-by-step explanations as training targets. This creates an internal capability for simulating execution without actually running the code. In the second phase, reinforcement learning fine-tunes the model on competitive programming tasks where the reward signal comes from verifiable execution—either comparing against ground-truth outputs or checking if the model's self-predicted execution matches the actual execution of its generated code. During inference, the model can generate code, simulate its execution step-by-step, detect errors in its simulation, and iteratively refine the code before submission. The key architectural component is that execution simulation is embedded in the model's forward pass, allowing it to use intermediate execution predictions as context for downstream code refinement.

Production Impact

For teams building code-generation systems (AI coding assistants, automated testing, program synthesis), this approach dramatically improves correctness on non-trivial tasks by adding introspection capability—the model can reason about whether its code will actually work before committing it. In production pipelines, you would integrate execution simulation as part of the code generation loop: generate candidates, have the model simulate execution on test cases, rank candidates by simulation accuracy, and only return high-confidence outputs. The trade-off is moderate: inference latency increases (2-3x longer generation due to simulation steps), but you eliminate expensive post-hoc testing and reduce false-positive code submissions. Integration requires fine-tuning on your domain's execution traces and building a lightweight execution sandboxing layer, but provides measurable ROI through higher first-pass correctness and reduced human review overhead.

Limitations and When Not to Use This

The approach assumes execution traces can be reliably generated and annotated for training, which is expensive for diverse or domain-specific code. The model's ability to simulate execution is bounded by context length and the complexity of the code—it may struggle with long-running programs, non-deterministic execution, or code that interacts with external systems (file I/O, network calls, databases). The reinforcement learning component requires verifiable rewards, limiting applicability to domains where ground-truth outputs can be automatically computed; for tasks with subjective correctness (e.g., design patterns, code style), this approach provides less benefit. Additionally, the paper doesn't deeply explore how simulation accuracy degrades when the model must simulate unfamiliar libraries or language constructs it hasn't seen during training.

Research Context

This work builds on a growing body of research showing that intermediate reasoning capabilities improve LLM performance on complex tasks (similar to chain-of-thought prompting and process supervision). It extends prior work on code verification and execution-guided generation by making execution simulation a learned capability rather than a post-hoc check. The paper contributes to the competitive programming benchmark domain (likely evaluated on platforms like Codeforces or LeetCode), where execution-aware approaches have shown consistent gains. The research opens a broader direction: teaching LLMs to internalize the operational semantics of programming languages, potentially extending beyond code to other domains where step-by-step simulation of outcomes could improve decision-making.


:::tip Subscribe Get weekly breakdowns of papers like this in AI Letters - the newsletter for engineers building production AI systems. :::


Back to Research Lab → · Subscribe to AI Letters →

© 2026 EngineersOfAI. All rights reserved.