CLI-Gym: Scalable CLI Task Generation via Agentic Environment Inversion

Yusong Lin, Haiyang Wang, Shuzhe Wu, Lue Fan, Feiyang Pan, Sanyuan Zhao, Dandan Tu

TL;DR

CLI-Gym introduces an automated pipeline that scales up training data for environment-intensive tasks (like fixing broken dependencies or system configurations) by turning LLM agents into "saboteurs" that deliberately break healthy software environments. Fine-tuning models on these self-generated, inverted trajectories produces LiberCoder, which achieves a new open-source state-of-the-art on Terminal-Bench, outperforming models many times its size.

What Problem Does This Paper Address?

While AI agents have gotten remarkably good at writing code—thanks to massive datasets harvested from GitHub pull requests (e.g., SWE-bench)—they still struggle significantly when interacting with real-world runtime environments via a Command Line Interface (CLI). Tasks like resolving dependency hell, fixing broken system locales, or repairing misconfigured environment variables are highly "environment-intensive."

The bottleneck isn't a lack of interest; it's a lack of data. Unlike code changes, which are neatly tracked by version control systems like Git, environment histories are rarely recorded. Consequently, existing benchmarks for CLI manipulation (like Terminal-Bench) rely on scarce, manually written human examples, leaving open-source models with insufficient data to learn robust system-level troubleshooting.

Methods

To bridge this gap, the authors propose Agentic Environment Inversion. Instead of asking an agent to fix a bug, they use an LLM agent to create one.

Overview of the CLI-Gym pipeline, showing the transition from a healthy GitHub repository to an inverted, buggy task instance.

The CLI-Gym pipeline operates in three main stages:

  1. Initial Gold Environment Construction: The pipeline starts with a healthy "gold" environment—a Docker image built from a real-world GitHub repository where all unit tests pass.
  2. Environment Inversion via Sabotage: An LLM agent is given a target subset of unit tests and prompted to execute CLI commands to deliberately corrupt the environment (e.g., uninstalling packages, altering file permissions, or corrupting shared library headers) until those unit tests fail. The exact sequence of destructive actions is recorded as a Dockerfile snippet to ensure reproducibility.
  3. Problem Instance Generation: Once a failure is successfully induced, the pipeline uses an LLM to automatically synthesize a natural language issue description based on the error messages and the original target tests, creating a complete, verifiable CLI task.

Datasets

Using this automated pipeline, the authors generated the CLI-Gym Dataset, which includes:

  • 1,655 environment-intensive task instances derived from 29 popular open-source Python repositories (such as pandas, scrapy, and gunicorn).
  • 291 high-quality "Filtered-Success" trajectories, curated by filtering out trivial solutions or "cheating" behaviors (like reading cached Git logs) from an initial pool of 417 successful rollouts.

For evaluation, the authors used Terminal-Bench 1.0 (80 tasks) and Terminal-Bench 2.0 (89 tasks).

Key Insights and Ideas

  • Environment Inversion as a Scalability Engine: Reversing the problem space allows the automated generation of complex system-administration tasks without human annotation.
  • Environment Diversity Trumps Trajectory Quantity: Through ablation studies, the authors found that fixing the training budget to 100 trajectories but scaling up the number of source repositories consistently improved performance. Exposing the model to diverse system configurations matters more than just showing it more examples from the same environment.
  • Escaping the "Action Loop" Trap: One of the most striking behavioral changes in models trained on CLI-Gym data was a massive drop in repetitive action loops (where an agent gets stuck running the same failing command). Supervision on environment repairs teaches the agent how to pivot and escape unproductive interaction patterns.

Key Results

The authors fine-tuned Qwen3-32B and Qwen3-235B-A22B-Instruct on their curated trajectories, naming the resulting models LiberCoder-32B and LiberCoder-235B-A22B.

Figure 1. Illustration of the idea behind our CLI-Gym that brings high performance on the Terminal-Bench 1.0. (a): Code-intensive tasks, as those in the SWE-bench, can be derived with readily available code histories and context like PRs. For tasks involving intensive interaction with the environment like CLI, as those in the Terminal-Bench, we employ agents to simulate and explore environment histories guided by execution feedback, realizing scalable derivation of environmen-intensive tasks. (b): With task trajectories obtained using our CLI-Gym, the fine-tuned Qwen3-32B and Qwen3-235B-A22B-Instruct models, named as LiberCoder and denoted by red triangles, achieve Pass@1 metrics of 38.9% and 46.1%, respectively, outperforming various strong baselines.
  • State-of-the-Art Open-Source Performance: LiberCoder-235B-A22B achieved a 46.1% Pass@1 on Terminal-Bench 1.0, representing a massive +21.1% absolute improvement over its base model.
  • Defeating the Giants: At just 32B parameters, LiberCoder-32B scored 38.9% on Terminal-Bench 1.0, outperforming much larger models like Qwen3-Coder-480B and the ~1-trillion-parameter Kimi-K2-Instruct.
  • Broad Category Gains: The model showed performance jumps exceeding 20 points across core environment categories, including software engineering, system administration, security, and debugging.

Limitations and Future Work

Despite its success, the authors note a few key limitations:

  • Domain Gaps: The automated pipeline struggled to generate meaningful tasks for specific domains like gaming and scientific computing, where unit tests are harder to invert effectively.
  • Context Window Explosion: Because fine-tuned models engage in more extensive, multi-step environment exploration, they are more prone to exceeding maximum inference context lengths (128k tokens), highlighting a need for future optimization in agent efficiency.

Summary updated

BibTeX
@misc{lin2026cli,
  author = {Yusong Lin and Haiyang Wang and Shuzhe Wu and Lue Fan and Feiyang Pan and Sanyuan Zhao and Dandan Tu},
  title = {{CLI-Gym: Scalable CLI Task Generation via Agentic Environment Inversion}},
  year = {2026},
  eprint = {2602.10999},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.10999},
}
Figure