Repo2Run: Automated Building Executable Environment for Code Repository at Scale

Ruida Hu, Chao Peng, X Wang, Chong Gao, Gao, Cuiyun

Abstract

Scaling up executable code data is significant for improving language models' software engineering capability. The intricate nature of the process makes it labor-intensive, time-consuming, and expert-knowledge-dependent to build a large number of executable code repositories, limiting the scalability of existing work based on running tests. The primary bottleneck lies in the automated building of test environments for different repositories, which is an essential yet underexplored task. To mitigate this gap, we introduce Repo2Run, the first LLM-based agent aiming at automating the building of executable test environments for any repositories at scale. Specifically, given a code repository, Repo2Run iteratively builds the Docker image, runs unit tests based on the feedback of the building, and synthesizes the Dockerfile until the entire pipeline is executed successfully. On a benchmark of 420 Python repositories, Repo2Run achieves an 86.0% success rate, outperforming SWE-agent by 77.0%.

Introduction

In the field of AI for software engineering, there is a stark contrast between the availability of static code and executable code. While static code is abundant, executable code—code that can be compiled, run, and tested—is a rare and valuable resource. To train or evaluate language models on real-world tasks like bug fixing or feature implementation, an environment where the code actually functions is indispensable.

Currently, building these environments is a significant hurdle. It requires manual effort to identify dependencies, resolve version conflicts, and configure system-level tools. This "it works on my machine" problem has historically limited researchers to small, hand-curated datasets. Existing LLM agents often fail in this domain because they "pollute" their environment: a single failed installation command can leave a mess of broken files that makes all subsequent attempts fail.

The Challenge of Environment Pollution

A major obstacle in automated environment building is the "pollution" of the workspace. When an agent attempts to install a package or run a configuration command that fails, it often leaves the system in an inconsistent state. For example, a partial installation might leave behind metadata that prevents a different version of the same package from being installed later.

The environment pollution problem: failed commands can leave a system in an inconsistent state, causing subsequent build steps to fail.

As illustrated in the figure above, a failed execution of a command can lead to unexpected changes in the environment, which subsequently causes building failures when those commands are added to a Dockerfile. This creates a "dependency hell" that standard LLM agents are ill-equipped to navigate without a mechanism to reset or backtrack.

Methodology: The Repo2Run Architecture

Repo2Run treats environment building as an iterative, trial-and-error process, utilizing a specialized architecture to overcome the pollution problem:

  1. Dual-Environment Architecture: The system is split into an Internal Environment (a Docker container where the agent performs active work like installing packages) and an External Environment (a controller that manages high-level state). This allows the system to swap base images or reset the workspace without the agent losing its context.
  2. Adaptive Rollback: This is the core innovation. Before every command, the system takes a snapshot. If a command fails or causes pollution, Repo2Run instantly rolls the environment back to its last known good state, allowing the agent to try a different approach from a clean slate.
  3. Dockerfile Synthesizer: Rather than asking an LLM to generate a Dockerfile from scratch—which often leads to hallucinations—Repo2Run records the successful trajectory of commands used to pass the tests. It then programmatically cleans and compiles these commands into a final, reproducible Dockerfile.

Evaluation and Results

To evaluate Repo2Run, we created a new benchmark consisting of 420 Python repositories scraped from GitHub in late 2024. These projects were selected based on having at least 100 stars and a functional suite of unit tests, covering diverse domains such as AI/ML, NLP, and Data Visualization.

Repo2Run achieved a 86.0% success rate, successfully building and running tests for 361 out of 420 repositories. This represents a massive lead over existing solutions. For comparison, we tested SWE-agent, a leading coding agent, which struggled with the complexities of environment setup.

Common failure modes of existing agents like SWE-agent, including dependency conflicts, incompatible base images, and missing environment variables.

As shown in the analysis of failure modes, existing agents frequently fail due to dependency missing/conflicts, incompatible base images, or missing environment variables. Repo2Run's iterative feedback loop and rollback mechanism allow it to navigate these issues where other agents simply stall or fail.

Conclusion

Repo2Run demonstrates that automated, large-scale environment building is possible by combining LLM reasoning with robust system-level controls like adaptive rollback. By achieving an 86% success rate, it provides a scalable path for generating the high-quality, executable datasets necessary to advance the state of the art in AI-driven software engineering.

Summary updated

Abstract

Scaling up executable code data is significant for improving language models' software engineering capability. The intricate nature of the process makes it labor-intensive, time-consuming and expert-knowledge-dependent to build a large number of executable code repositories, limiting the scalability of existing work based on running tests. The primary bottleneck lies in the automated building of test environments for different repositories, which is an essential yet underexplored task. To mitigate the gap, we introduce Repo2Run, the first LLM-based agent aiming at automating the building of executable test environments for any repositories at scale. Specifically, given a code repository, Repo2Run iteratively builds the Docker image, runs unit tests based on the feedback of the building, and synthesizes the Dockerfile until the entire pipeline is executed successfully. The resulting Dockerfile can then be used to create Docker container environments for running code and tests. We created a benchmark containing 420 Python repositories with unit tests for evaluation. The results illustrate that Repo2Run achieves an 86.0% success rate, outperforming SWE-agent by 77.0%. The resources of Repo2Run are available at https://github.com/bytedance/Repo2Run.
BibTeX
@inproceedings{hu2025repo,
  author = {Ruida Hu and Chao Peng and X Wang and Chong Gao and Gao, Cuiyun},
  title = {{Repo2Run: Automated Building Executable Environment for Code Repository at Scale}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=fZsd3KLMje},
}
Figure