RL ENVIRONMENTS FOR LLMs
Why environments matter
Environment - the place where a model is trained and evaluated. Classic RL already had them: gym / gymnasium for Atari, chess, Go.
- Post-training an LLM
- Evaluating a model
- Generating synthetic data (run models on dataset questions, keep high-quality QA pairs)
- Evaluating and experimenting on a harness
Build one good environment once. Reuse it many ways. Why the hype: every lab goes through post-training. More and better environments (coding, maths, science, computer use, browser use) means better models. Example: Intellect-3 from Prime Intellect, trained on a fully open-source stack.
Open-source angle: find a task where models are weak, turn it into an environment, publish it. A lab may use it in its next training run.
Mapping classical RL to an LLM
| RL term | Meaning | In an LLM chat |
|---|---|---|
| State | Where the agent currently is | Conversation history, steps taken so far |
| Action | What the agent does next | Next token or full response |
| Environment | Returns next observation and reward | The chat window / task setup |
| Reward | Did it do good or bad, and how much | Score on the evaluation task |
| Policy | Brain of the agent | The LLM powering it |
The environment trinity: dataset, rollout, rubric
| Part | School exam analogy | Role |
|---|---|---|
| Dataset | List of questions | Input to the environment |
| Rollout | Student's answers (and retries after feedback) | The whole loop of action, next state, reward |
| Rubric | How the teacher grades | Assigns reward |
Rubric varies by task. MCQ or one-word answer -> exact match. Subjective maths paper -> partial marking for steps. Real datasets: GSM8K, Tau-bench, SWE-bench, BrowseComp (school maths to PhD maths, GitHub issues, research, computer use).
Types of rollout
- Single turn - one prompt, one answer.
- Multi-turn - answer, get feedback (right/wrong), try again, up to an allowed number of turns.
- Tool use - model can call tools like web search or a calculator.
- Sandbox - isolated machine where the model runs any code, even malicious or vulnerable, without affecting anything real.
Single-turn environments are mostly used for benchmarks and evaluation. Multi-turn, tool use, computer use and browser use are where real RL training happens. For both, build both versions.
Types of rubric
- Verifiable - exact match or tests. Pass or fail, a binary signal.
- LLM judge - rules in a system prompt, returns a score such as 0.13 or 0.57. Used for subjective tasks (essay, story, poem).
- Hybrid - use both together.
Reward hacking
Reward hacking - the model finds a shortcut that earns reward without doing the real task.
Example
Task: judge essays. Judge rule: a certain style of opening gives +3 points. The model learns that starting every response with that phrase earns +3 regardless of content. Rewards climb. Real essay-judging skill stays the same. Similar: starting with "great question".
Why verifiable rewards are unhackable (in principle)
- Binary signal: right or wrong, nothing in between. (Step function)
- Small output space to exploit. Why LLM judges are hackable
- Reward is fluid; moves up a bit at a time.
- Large sample space; also judges style, readability, language.
- Easy to miss something the agent can exploit.
If an environment has any edge case, the model will find it and exploit it. Money gets wasted while the model improves at nothing. Always compare rewards with a real evaluation.
Evaluating harnesses: Terminal-Bench
Terminal-Bench - benchmark of tasks for coding agents (Codex, Claude Code, OpenCode, etc.) working in a terminal.
- Each task: instruction (e.g. work on a COBOL program at a file path), categories like software engineering and games, difficulty easy to hard.
- Leaderboard ranks agent + model combinations.
- Big companies train on similar environments and keep private evaluation sets next to public ones.
Open-source ecosystem
- verifiers (Prime Intellect) - prebuilt single-turn, multi-turn, tool and code environments, rubrics, parsers. Handles edge cases needed at scale.
- Environments Hub - open registry to download and publish environments.
- OpenEnv (Meta + Hugging Face) - Gymnasium-style, reset/step type functions, runs tasks in local environments.
- RL frameworks: prime-rl (async distributed), TRL (Hugging Face), SkyRL, Tinker.
Environments do not depend on the RL framework. The same environment works in prime-rl, TRL or on Tinker. (Portable)
Building an environment from scratch
- Dataset - 5 common CS problems (add, is even, reverse string...). Each has problem id, prompt, function name, 4 tests.
- Sandbox - model code is not run on your machine. Here a Python subprocess with timeout mimics it. Real sandboxes are far more complex.
- Rollout - system prompt: python coding agent, respond with only the function definition, no markdown. Max 300 tokens.
- Rubric - run generated code against the tests, return per-test results.
- evaluate() - rollout then rubric for the full dataset.
Pipeline: problem -> rollout (model writes code) -> sandbox runs tests -> rubric score.
First run gave 0% passing even on trivial problems. The code was correct, but the model wrapped it in markdown backticks. Backticks are invalid Python syntax, so every test errored.
Add a parser: strip the backticks and other wrapping, then run. Pass rate then became correct.
Parser - component that pulls structured information (runnable code) out of unstructured model output. Real environments need one. Even the biggest environment is just dataset + rollout + rubric at its core.
Same environment with the verifiers library
- Convert dataset to Hugging Face Dataset: question = prompt, answer = function name, info = tests.
- Rubric = two reward functions: code passes tests (weight 5), code is parseable (weight 1). Two functions makes it a hybrid rubric. Passing matters most.
- Create single-turn environment with dataset, system prompt, rubric.
- Evaluate with config: model, number of examples, rollouts per example, max tokens.
~70-80 lines of raw code became ~30 lines. Same behaviour; better abstractions, async runs, parsers (strips XML tags and thinking), hub sharing, direct link to prime-rl training.
Multi-turn and comparing models
Multi-turn: model writes code, failure output goes back to it, it fixes the code, repeat until it passes or max turns is reached. In verifiers you define how the environment responds and an is-completed condition (all turns used or task done).
| Model | Pass rate |
|---|---|
| Gemini | 100% |
| GPT-4o mini | 60% |
| Small open model | 20% |
Differences come from output format: some models add backticks, others need much more parsing. With an existing dataset (e.g. GSM8K) you only write the rollout and rubric.
Training later: GRPO. Run several rollouts per prompt, use the group average to update the policy.
What to build and what to explore
- Easy: reverse text, unscramble words, sorting.
- Multi-turn practice: Wordle, connections puzzle.
- Harder: own Terminal-Bench-style questions, Tau-bench, BrowseComp, environments from new research papers.
- Prime Intellect gives bounties for environments.
- Open questions: which domain, how to handle non-verifiable rewards and hacking, what changes when rubric takes seconds not milliseconds, LLM judge vs tool-based checks.
Outcome reward model (ORM) - reward on the final output. Process reward model (PRM) - reward on every step, e.g. each step of a maths solution. Also read: elicit vs create debate, sandboxes (systems), synthetic data generation.
Glossary
- Environment
- Dataset, rollout and rubric together; where a model is trained or evaluated.
- Rollout
- How the model interacts with the dataset: actions, next states, feedback.
- Rubric
- The function that assigns reward to a rollout.
- Reward hacking
- Exploiting rubric flaws to get reward without real capability gain.
- Sandbox
- Isolated machine where model-generated code runs safely.
- Parser
- Component that extracts structured, usable output from raw model text.
- verifiers
- Prime Intellect library for building RL environments.
- Harness
- The agent scaffold around a model, such as a terminal coding agent.