AgentExecutor: Partial Code Execution via Agentic Context Generation

Junkai Chen, Chengran Yang, Xing Hu, Zhenhao Li, Xin Xia, David LoarXiv 2026

TL;DR

AgentExecutor is a novel multi-agent framework that automatically makes arbitrary, incomplete code snippets executable by dynamically generating the necessary context and environment configurations. By combining autonomous LLM agents with smart context pruning and program synthesis, it achieves up to 94% code coverage while slashing execution time by up to 80.3% and monetary costs by over 50% compared to state-of-the-art baselines.

What Problem Does This Paper Address?

Dynamic program analysis tools—like fuzzers, debuggers, and performance profilers—are incredibly useful, but they all share a common prerequisite: the code must actually run. Unfortunately, executing an arbitrary code snippet found on Stack Overflow or isolated from a large GitHub repository is notoriously difficult. These "partial code" snippets frequently suffer from missing imports, uninitialized variables, and missing environment dependencies.

Prior approaches (such as LExecutor and Treefix) leverage language models to guess missing values or build prefix trees of code context. However, they operate under two major constraints:

  1. Limited Action Spaces: They cannot interact with the underlying operating system to do things like create required resource directories or flexibly install packages.
  2. Rigid Optimization Strategies: They often query LLMs a fixed number of times regardless of whether coverage has already saturated, leading to high latencies and excessive API costs.

Methods

AgentExecutor addresses these limitations using a specialized multi-agent architecture divided into three distinct phases:

Figure 1: Overview of AgentExecutor, which consists of three phases: (i) Execution Environment Preparation, (ii) Dynamic Exploration with Iterative Refinement, and (iii) Prefix Evolution via Program Synthesis. Given the partial code, we first (i) prepare the execution environment by attempting to execute, supported by EnvAgent, then (ii) iteratively generate and refine prefixes where we design dynamic pruning and friendly feedback for RefAgent, and finally (iii) produce a generator program to evolve more prefixes from selected seed prefixes.
  1. Execution Environment Preparation (EnvAgent): Instead of using a shared, static environment, AgentExecutor provisions an isolated virtual environment for each snippet using uv (a high-performance Python package manager). The EnvAgent attempts to run the code, catches system-level errors via a bash tool, and autonomously fixes environment issues (e.g., installing missing libraries or creating placeholder files).
  2. Dynamic Exploration with Iterative Refinement (RefAgent): The RefAgent inspects the partial code to generate code "prefixes" (initialization statements placed before the snippet). To prevent the LLM from getting confused by long histories of failed execution attempts (attention dilution), the authors introduce Coverage-Aware Dynamic Context Pruning. If a branch of exploration fails to improve code coverage after a set number of attempts, that history is wiped from the agent's context window.
  3. Prefix Evolution via Program Synthesis (EvoAgent): Rather than repeatedly asking an LLM to guess different variable values, AgentExecutor uses meta-programming. The EvoAgent takes high-value "seed" prefixes and synthesizes a generator program (e.g., nested loops iterating through potential variable values). Running this synthesized script locally generates thousands of prefix combinations instantly, entirely bypassing expensive LLM API calls.
Figure 4: A simplified, illustrative example of the prefix evo- lution.

Datasets

The authors evaluated AgentExecutor on two widely accepted benchmarks in partial code execution research:

  • Stack Overflow Snippets: 462 Python code snippets extracted from real answers on the platform.
  • Open-Source Functions: 1,000 functions sampled from popular GitHub repositories, including black, tensorflow, scrapy, flask, and pandas.

Key Insights and Ideas

  • Meta-Generation is Cheaper Than Direct Generation: One of the biggest "aha" moments of the paper is the use of the EvoAgent. Writing a script that generates code variations locally is vastly more efficient than treating the LLM as a brute-force search engine.
  • Context Pruning Acts as Early Stopping: LLMs easily get trapped in "error loops" when fed a long history of failures. Dynamically cutting out low-value exploratory paths keeps the agent focused and significantly lowers token costs.
  • Environment Mocks Matter: Code execution doesn't just fail because a variable is missing; it fails because of environmental mismatches (e.g., a hardcoded Windows file path being executed in a Linux Docker container). Giving agents full bash access allows them to dynamically catch and mock these OS-level dependencies.

Key Results

AgentExecutor significantly outperformed all baseline methods across both datasets:

  • Code Coverage: It achieved 94% line coverage on Stack Overflow snippets and 90% on open-source functions, outperforming the previous state-of-the-art tool (Treefix) by 19.9% and 13.8% respectively.
  • Full Execution Rate (FER): It successfully executed 100% of the lines in 36.1% more Stack Overflow snippets and 18.1% more GitHub functions than Treefix.
  • Efficiency Gains: AgentExecutor reduced average execution time by 77.9% to 80.3% and cut monetary API costs by 52.1% to 56.6%, thanks to halving the total number of required LLM invocations.

Limitations and Future Work

The authors noted that LLM agents occasionally suffer from premature termination, where an agent stops its execution loop early and leaves a trajectory incomplete, degrading downstream performance. A key area for future work is customizing the agent harness to automatically detect these silent early exits and force a recovery routine. Additionally, the authors plan to expand the diversity and granularity of the evaluation datasets beyond Python.

Summary updated

BibTeX
@misc{chen2026agentexecutor,
  author = {Junkai Chen and Chengran Yang and Xing Hu and Zhenhao Li and Xin Xia and David Lo},
  title = {{AgentExecutor: Partial Code Execution via Agentic Context Generation}},
  year = {2026},
  eprint = {2608.05959},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2608.05959},
}
Figure