R2E: Turning any Github Repository into a Programming Agent Environment

Naman Jain, Manish Shetty, Tianjun Zhang, King Han, Koushik Sen, Ion Stoica

Introduction

While Large Language Models (LLMs) have made significant strides in coding capabilities, evaluating them on real-world programming setups remains a challenge. Most current benchmarks, such as HumanEval or MBPP, consist of isolated "toy" problems with simple input/output types and no external dependencies. However, real-world software engineering occurs within massive codebases where a single function might rely on dozens of custom classes, external libraries, and specific file system setups.

The primary hurdle in building better benchmarks is scalability. Manually writing high-quality test suites for thousands of real-world functions is unfeasible. Furthermore, predicting the exact output of a complex function is extremely difficult for an LLM. To address this, researchers have introduced Repository to Environment (R2E), a novel framework that automatically transforms any GitHub repository into a fully interactive sandbox for evaluating AI coding agents.

The R2E Framework

R2E automates the creation of execution-based environments directly from "wild" code found on GitHub. It moves beyond simple code completion to test how models handle complex, real-world software dependencies.

The R2E pipeline transforms GitHub repositories into interactive coding environments.

The framework follows a sophisticated pipeline to turn a repository into a testbed:

  1. Dependency Slicing: Instead of overwhelming a model with an entire repository, R2E uses callgraphs and bytecode analysis to extract a "slice"—the minimal set of functions and global variables a specific function needs to run.
  2. Equivalence Test Generation: This is the core innovation of R2E. Rather than asking an LLM to predict a specific output, R2E generates a test harness that uses the original GitHub code as a "ground truth" oracle. The test runner executes both the original code and the LLM-generated code on the same inputs and checks if the results are functionally equivalent.
  3. Specification Refinement: Because GitHub docstrings are often messy or missing, R2E uses an LLM to "self-instruct" and refine the function's description into a clear, actionable prompt, using synthesized test cases as additional context.
  4. Interactive Environment: R2E sets up a Dockerized environment with an interpreter, allowing "agentic" models to run their code, see error traces, and self-repair.
R2E generates an equivalence test harness by leveraging external and in-file context to compare generated code against the original implementation.

R2E-Eval1 Benchmark

Using this framework, the authors introduce R2E-Eval1, a fully executable benchmark providing automated, high-coverage test harnesses.

  • Composition: 246 tasks extracted from 137 distinct GitHub repositories.
  • Complexity: Tasks include an average of 3.7 dependencies and 11.5 test cases per problem.
  • Diversity: It covers 70 unique APIs and 118 unique argument types, ranging from standard Python types to complex objects from libraries like NumPy, Pandas, and PyTorch.

Key Insights and Results

  • Decoupling Inputs from Outputs: By using the original code as a reference implementation, the framework avoids the "oracle problem." The system only needs to verify if the new code behaves exactly like the old code, rather than knowing the exact expected output beforehand.
  • The "Sliced" Sweet Spot: Providing the model with just the "sliced" dependency context performs as well as (or better than) providing the full file context. It reduces noise and fits better within LLM context windows.
  • Benchmark Difficulty & Model Behavior: State-of-the-art models perform significantly worse on R2E-Eval1 than on HumanEval, highlighting a massive "reality gap." LLMs often struggle to understand interfaces to existing functions and frequently "reinvent the wheel" by re-implementing existing helper functions rather than reusing the provided context.
  • The Power of Interaction: Static prompting techniques like Chain-of-Thought (CoT) did not significantly improve performance on these complex tasks. However, allowing the model to interact with the R2E environment—using error feedback to self-repair—boosted the success rate of models like GPT-4 by 33% over five iterations.
  • Validity & Coverage: The R2E pipeline successfully generates valid test harnesses for ~44% of candidate functions, achieving an impressive average of 83% branch coverage, ensuring rigorous evaluation.

Limitations and Future Work

While R2E presents a significant leap forward, it has limitations. Natural language docstrings remain inherently ambiguous, and even with refinement, some corner cases might be missed. Additionally, the framework currently relies on "observational equivalence" (checking if outputs match); future work could incorporate mutation testing for even higher confidence. Finally, while the framework's methodology is general, the current implementation and benchmark are focused on Python, meaning expansion to languages like Rust or C++ will require overcoming new program analysis challenges.

Summary updated

BibTeX
@inproceedings{jain2024r,
  author = {Naman Jain and Manish Shetty and Tianjun Zhang and King Han and Koushik Sen and Ion Stoica},
  title = {{R2E: Turning any Github Repository into a Programming Agent Environment}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=kXHgEYFyf3},
}
Figure