An LLM-based Agent for Reliable Docker Environment Configuration

Ruida Hu, Chao Peng, Xinchen Wang, Cuiyun Gao

Abstract

Creating executable Docker environments for arbitrary code repositories is a manual and error-prone task. We present Repo2Run, an LLM-based agent that automates this process using a dual-environment architecture and an adaptive rollback mechanism. Repo2Run achieves an 86% success rate in building runnable environments on a benchmark of 420 Python repositories, significantly outperforming existing general-purpose agents like SWE-agent.

Introduction

In the field of AI for Software Engineering, the ability to execute code is essential for training and evaluating models. However, configuring a random GitHub repository to run successfully is notoriously difficult due to complex dependencies, specific runtime requirements, and poor documentation. Currently, researchers must choose between unreliable static analysis tools or labor-intensive manual Dockerfile creation.

The standard workflow for creating executable instances from code repositories, often requiring manual environment building.

General-purpose LLM agents often fail at this task because they lack specialized environment-building actions and frequently "pollute" the environment—executing a command that fails halfway through and leaves the system in a broken, unrecoverable state. Repo2Run addresses these challenges by automating the iterative process of environment configuration.

Methodology

Repo2Run employs a specialized agentic workflow designed for robustness and reproducibility:

1. Dual-Environment Architecture

The system operates across two distinct layers: an Internal Environment (a Docker container for package installation and testing) and an External Environment (a terminal managing the container). This separation allows the agent to perform high-level system changes, such as modifying the base OS image or Python version, which cannot be done from within the container itself.

2. Adaptive Rollback Mechanism

To solve the "pollution" problem, Repo2Run implements an adaptive rollback strategy. Before executing potentially destructive commands (e.g., pip install), the system snapshots the container state using docker commit. If a command fails, the agent immediately reverts to the last known good state, preventing "dependency hell" caused by partial installations.

Comparison between environment pollution caused by failed commands and building failures in a Dockerfile.

3. Specialized Action Set and Synthesis

The agent utilizes nine specialized actions for environment monitoring, dependency management, and iterative testing. Once a successful build trajectory is established and unit tests pass, Repo2Run programmatically synthesizes a clean, reproducible Dockerfile by replaying the successful command sequence.

Evaluation and Results

The researchers evaluated Repo2Run using a new benchmark of 420 Python repositories crawled from GitHub in 2024, ensuring no data leakage into the LLM's training set.

  • Success Rate: Repo2Run achieved an 86.0% Environment Building Success Rate (EBSR), vastly outperforming the SWE-agent (9.0%) and standard LLM-based Dockerfile generation (22.1%).
  • Dockerfile Quality: The system achieved a 100% Dockerfile Generation Success Rate, producing syntactically valid and buildable files for every successful environment.
  • Efficiency: The average build time was approximately 29 minutes, comparable to human experts (21 minutes) but without requiring manual intervention.

Discussion and Limitations

The study highlights that dynamic execution is superior to static analysis for environment configuration. The rollback mechanism was identified as the most critical factor in achieving high reliability. However, limitations remain: 45.8% of failures were attributed to external factors such as missing API tokens, hardware constraints (e.g., GPU requirements), or defects in the source repository's tests. Future work will focus on expanding support to other programming languages and optimizing build trajectories to reduce Docker image size.

Conclusion

Repo2Run demonstrates that specialized LLM agents can effectively automate complex system administration tasks. By combining a dual-environment approach with state-aware rollbacks, it provides a scalable solution for the "it works on my machine" problem in software engineering research.

Citation: Ruida Hu, et al. "Repo2Run: Automated Building Executable Environment for Code Repository at Scale." NeurIPS 2025.

Summary updated

BibTeX
@inproceedings{hu2025llm,
  author = {Ruida Hu and Chao Peng and Xinchen Wang and Cuiyun Gao},
  title = {{An LLM-based Agent for Reliable Docker Environment Configuration}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=fZsd3KLMje},
}
Figure