TL;DR
Repo2Run is an LLM-based agent designed to solve the "it works on my machine" problem at scale by automatically building executable Docker environments for any code repository. By combining a dual-environment architecture with a specialized "rollback" mechanism, it achieves an 86% success rate in environment building, vastly outperforming existing general-purpose coding agents.
What Problem Does This Paper Address?
To improve the software engineering capabilities of Large Language Models (LLMs), researchers need massive amounts of executable code data—code that doesn't just look right but actually runs and passes tests. However, building the environments required to run these tests is a major bottleneck.
Currently, this process is labor-intensive and expert-dependent. A developer must manually select a base image, install complex dependencies, set environment variables, and debug cryptic build errors. Existing automated tools often fail because they lack specialized actions for environment management. For instance, if a command partially installs a package and then fails, it "pollutes" the environment, making subsequent attempts unstable. This lack of scalability limits the creation of large-scale benchmarks for evaluating and training coding LLMs.
Methods
The authors introduce Repo2Run, an agentic framework that navigates the environment-building process through an iterative feedback loop. Its architecture consists of three main components:
- Dual-Environment Architecture:
- Internal Environment: A Docker container where the agent executes actions like running tests and installing packages.
- External Environment: A terminal-like bridge that allows the agent to perform "meta" actions prohibited inside the container, such as changing the base image (e.g., switching from Python 3.10 to 3.11).
- Adaptive Rollback Mechanism: To handle "environment pollution," Repo2Run takes a snapshot (using
docker commit) before executing risky commands. If a command returns a non-zero exit code, the system automatically reverts the environment to its clean, pre-execution state. - Dockerfile Synthesizer: Once the agent successfully runs all unit tests, Repo2Run doesn't just hand over a container. It programmatically converts the successful command trajectory into a clean, reproducible Dockerfile by mapping actions to keywords like
FROM,ENV,COPY, andRUN.
Datasets
The authors created a new, rigorous benchmark to evaluate Repo2Run:
- 420 Python Repositories: Crawled from GitHub in 2024 to ensure no data leakage (as these repos wouldn't have been in the training data of current LLMs).
- Selection Criteria: Repositories must have at least 100 stars and contain valid unit tests (using
pytestorunittest). - Diversity: The benchmark spans domains including AI/ML (the largest share at ~63%), Software Engineering, NLP, and Data Visualization.
Key Insights and Ideas
- Pollution is the Silent Killer: The paper highlights that failed commands are rarely "no-ops." They often leave behind orphaned files or conflicting package versions that break the rest of the build. The rollback mechanism is the "aha moment" that allows the agent to explore valid trajectories without getting stuck in a corrupted state.
- Trajectory $\neq$ Dockerfile: You cannot simply dump a bash history into a Dockerfile. Repo2Run intelligently filters out "safe" commands (like
lsorcat) and handles directory changes (cd) to ensure the final Dockerfile is optimized and functional. - Base Image Flexibility: LLMs often struggle to guess the correct environment requirements from a README alone. By allowing the agent to dynamically change the base image based on execution errors (e.g., seeing a
ModuleNotFoundErrorfor a standard library class only available in newer Python versions), Repo2Run mimics human troubleshooting.
Key Results
Repo2Run sets a new state-of-the-art for automated environment building:
- 86.0% Success Rate: It successfully built environments for 361 out of 420 repositories.
- Massive Improvement over Baselines: It outperformed SWE-agent (which achieved only 9.0%) by a staggering 77%. It also beat simple LLM-based Dockerfile generators (22.1%) and automated tools like
pipreqs(6.0%). - Efficiency: The average build time was approximately 29 minutes, which is comparable to manual effort by a human expert but requires zero human intervention.
- High Quality: Using
hadolint(a Dockerfile linter), the authors showed that Repo2Run produces cleaner, higher-quality Dockerfiles with fewer warnings than other automated methods.
Limitations and Future Work
- Language Support: The current implementation is focused exclusively on Python. Expanding to other languages like C++, Java, or Go would introduce new challenges in dependency management (e.g., CMake, Maven).
- External Dependencies: Some failures (about 35% of failed cases) were due to "Hardware Insufficiency" or "Missing Tokens" (e.g., requiring a private API key). These are external to the agent's logic but represent a hurdle for full automation.
- Complex System Dependencies: While Repo2Run handles Python packages well, repositories requiring complex system-level drivers (like specific CUDA versions) still pose a challenge for fully autonomous agents.
Summary updated