Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
RL environments
engineering.
The reasoning models everyone celebrates are trained by reinforcement learning — but the algorithm gets too much of the credit. What actually teaches the model is the environment: which tasks it attempts, how hard they are, and how a verifier grades them. Get the environment wrong and the best RL algorithm learns nothing, or worse, learns to cheat. This handbook is the build side of verifiable rewards: how to engineer tasks and verifiers that produce a clean, learnable signal.
The environment is the teacher
In reinforcement learning from verifiable rewards, a model attempts a task, a verifier scores the attempt, and the score nudges the policy. The verifiable-rewards handbook covers why this works and how it fails — reward hacking, verifier gaming. This one is the other half: how to build the environment so the signal is worth learning from.
And the environment is everything the model learns from. Two levers dominate: the tasks (which problems, at what difficulty) and the verifier (how correctness is judged). Both have a measurable failure mode that no amount of algorithmic cleverness fixes — and both are quantifiable, which is what the rest of this handbook does.
Learning lives in the difficulty band
Policy-gradient RL learns by comparing better attempts to worse ones. So the signal depends on there being a spread. For a pass/fail task with success probability p, the reward variance — a proxy for the gradient magnitude — is p(1−p). That's a hill: zero at the ends, maximal in the middle.
A task the model always solves (p=1) or never solves (p=0) has zero variance — every attempt gets the same reward, so there's nothing to learn from. The productive tasks are the ones it solves sometimes.
p→1, all pass
signal ≈ 0
p≈0.5
signal MAX
p→0, all fail
signal ≈ 0
This is why a curriculum matters: as the model improves, tasks that used to sit at p≈0.5 drift toward p≈1 and stop teaching. A good environment continuously supplies tasks in the band — hard enough to fail sometimes, easy enough to succeed sometimes. The runnable model below plots the signal hill.
Verifier soundness: what you reward is what you get
The task sets the difficulty; the verifier sets the truth. And a verifier that can be fooled is worse than useless — it produces false positives, rewarding trajectories that are actually wrong. The model, being an excellent optimizer, learns to satisfy the verifier rather than solve the task. That's reward hacking, and its root is a low-precision verifier.
Every false positive is a lie in the training data. A verifier that rewards 20 correct and 80 lucky-wrong trajectories has precision 0.2 — it's teaching the wrong lesson 80% of the time.
The theory of how models find and exploit these holes — verifier gaming, specification gaming — is in the verifiable-rewards handbook and the DeepSeek-R1 and GRPO breakdowns. The environment-engineering takeaway is simpler: precision is a first-class environment metric. Harden the verifier — exhaustive test cases, hidden tests, format and process checks — until a wrong answer can't pass.
Engineering the environment
| Lever | What to do |
|---|---|
| Difficulty curriculum | Keep tasks in the p≈0.5 band as the model improves; retire solved tasks, add harder ones. Adaptive difficulty beats a fixed set. |
| Verifier hardening | Maximize precision: hidden tests, adversarial cases, check the process not just the answer, so a lucky-wrong or gamed trajectory fails. |
| Diversity | Many task families prevent the model from overfitting one verifier's quirks; breadth is a hedge against narrow gaming. |
| Anti-gaming checks | Watch for degenerate solutions that pass the letter of the verifier — the classic sign a hole exists to patch. |
Two numbers summarize an environment's health: reward variance (is the task teaching anything?) and verifier precision (is it teaching the right thing?). A great environment keeps both high — tasks in the band, verifiers that can't be fooled. That's where the leverage in modern RL actually sits.
The interface: task, rollout, reward
Strip away the frameworks and every RL environment for LLMs is three functions. A task is what the model sees plus what it must not see. A rollout runs the model against the task, possibly over many turns of tool use. A reward grades the finished trajectory. It's the contract Gym made standard for classic RL, reset() then step(action) returning an observation, a reward and whether the episode is over, stretched to text. The observation is a conversation, and an action is a message or a tool call.
def rollout(policy, task, max_turns=8):
msgs = [user(task.prompt)]
for _ in range(max_turns): # multi-turn: tool calls until the model stops
reply = policy(msgs); msgs.append(reply)
if not reply.tool_call: break
msgs.append(sandbox.run(reply.tool_call, timeout=10))
return msgs
def reward(task, msgs):
r = sandbox.run_tests(final_code(msgs), task.hidden_tests, timeout=30, network=False)
return 1.0 if r.all_passed else 0.0
A framework-neutral sketch. Real libraries add batching, async rollouts and token bookkeeping, but the shape stays the same.
The sandbox carries the security model, because the policy is now writing code that you execute millions of times. Run every rollout in a fresh, isolated container. Cap CPU, memory and wall-clock time, and keep the network off unless the task needs it. Keep the hidden tests and the reward computation outside the container: a model that can read the tests will learn to read them, and a model that can edit them will learn to edit them. That's verifier soundness again, enforced by isolation rather than by cleverness. (The Sandboxing handbook and Design a Code Execution Sandbox cover the isolation layer.)
The shape scales to real software work. SWE-Gym (December 2024) packages 2,438 real-world Python tasks, each with a repository and a runnable environment, unit tests, and a task written in plain language. Its authors report up to 19% absolute gains in resolve rate on SWE-Bench Verified and Lite from training agents on it.
Filtering for the band: pass rates and dynamic sampling
The difficulty band from section 02 becomes a concrete filter once you can run rollouts. Sample k attempts per task with the current policy, grade them, and look at the pass rate. GRPO-style methods score each attempt against its own group, Ai = (ri − mean(r)) / std(r), so when all k rewards are equal every advantage is zero and the task contributes nothing but compute.
| Pass rate over k = 8 | What it means | Action |
|---|---|---|
| 0 / 8 | Too hard for the current policy (or the verifier is broken) | Park it and retry later. Check the reference solution passes. |
| 1–7 / 8 | In the band: some attempts beat others | Train on it. |
| 8 / 8 | Solved: zero advantage for every attempt | Retire it, or replace it with a harder variant. |
Run offline, this is difficulty filtering of the task pool. DAPO (ByteDance Seed and Tsinghua AIR, March 2025) does it online and calls it dynamic sampling: "over-sample and filter out prompts with the accuracy equal to 1 and 0," so every prompt in a batch carries gradient and the batch size stays constant. In the paper's ablation on Qwen2.5-32B, dynamic sampling was the last technique added, and it took AIME 2024 accuracy from 42 to 50. Naive GRPO had started at 30.
DAPO also shows what verifier hardening looks like in practice. Competition answers come as expressions and formulas that are hard to parse reliably, so the team had an LLM rewrite each question until its answer was an integer: a question whose answer is (a+√b)/c becomes one that asks for a+b+c. The result, DAPO-Math-17K, is 17K prompts that each have an integer answer, which a rule can check without a formula parser. The reward is just as plain: 1 if the answer is equivalent to the ground truth, −1 otherwise.
When there is no checker: rubrics, judges and partial credit
Rule-based rewards are a deliberate choice. DeepSeek-R1 paired an accuracy reward (a boxed final answer for math, compiler feedback on predefined test cases for LeetCode problems) with a format reward for putting the reasoning between think tags. Its authors skipped neural reward models for R1-Zero because they "may suffer from reward hacking in the large-scale reinforcement learning process." Much of the work people want trained, though, has no exact checker: a medical answer, a research summary, a support conversation.
The current answer is to make the grader structured. Rubrics as Rewards (July 2025) has an LLM judge score each response against a checklist of rubric criteria, and uses that score as the reward. Against judges that give one Likert score, the best variant reports relative gains of up to 31% on HealthBench and 7% on GPQA-Diamond, and rubric rewards held up better with smaller judges. A rubric also gives partial credit for free, because satisfying four of six criteria scores higher than satisfying two.
| Reward type | Signal | Main risk |
|---|---|---|
| Exact rule (answer match, all tests pass) | Sparse, high precision | Parser gaps; tasks outside the band teach nothing |
| Fraction of tests passed | Denser, partial credit | Rewards code that handles the easy cases and skips the hard one |
| Rubric + LLM judge | Works where nothing can be executed | The judge is a learned verifier, so it can be gamed like one |
Treat a judge the way section 03 treats any verifier. Measure its precision against human labels on a held-out set, re-check it as the policy improves, and watch for answers that score well on the rubric while getting worse to a human reader. The LLM-as-Judge Prompt Builder is a quick way to draft rubric criteria.
What the published recipes agree on
The open recipes converge on the same few environment decisions. Use rule-based rewards wherever a rule exists (DeepSeek-R1, DAPO). Reshape tasks until the rule is reliable (DAPO-Math-17K's integer answers). Filter out prompts the policy always or never solves (DAPO's dynamic sampling). Build real execution environments with hidden tests for agentic work (SWE-Gym). Environments are becoming shareable artifacts too: Prime Intellect's open-source verifiers library, "our library for creating environments to train and evaluate LLMs," is built around publishing them to its Environments Hub.
For an engineer entering this space, the mental model is refreshingly concrete: you're not tuning a mysterious learner, you're building a curriculum with a grader. Keep the tasks in the difficulty band, keep the grader honest, and the algorithm mostly takes care of itself. Get either wrong and no algorithm can save you.
The theory half: Verifiable Rewards. The algorithm: GRPO. The frontier proof: DeepSeek-R1. Practice the grader: Write a Verifier. Run it at scale: Design an RL Environment Farm.
The two numbers that grade an environment
An environment's health reduces to two computable numbers. The learning signal is the reward variance p(1−p): a hill that peaks when the model solves a task half the time and flatlines to zero when it always or never succeeds. The verifier precision is the fraction of rewarded trajectories that are genuinely correct — every false positive is a lie the model learns from. Watch a too-easy task teach nothing, and a gameable verifier corrupt the signal. Change the pass rate and the verifier's false positives.
Quick answers
What is RL environment engineering?
Designing the tasks, verifiers, and reward signals a reasoning model trains against. The environment is the entire training signal, so engineering it — difficulty, verifier soundness, diversity — matters as much as the algorithm.
Why does RL need reward variance?
Policy gradients learn by comparing better and worse attempts. A task always solved or never solved has constant reward and near-zero gradient. The signal scales with p(1−p) — maximal near a 50% pass rate, zero at the extremes.
How does a bad verifier hurt training?
A gameable verifier produces false positives, rewarding wrong trajectories. The model learns to satisfy the verifier, not solve the task — reward hacking. Verifier precision (correct ÷ all rewarded) is the environment's quality metric. The compounding version — a verifier that is wrong a little being wrong more every round — is worked through in self-improving agents.
How is this different from verifiable rewards?
The verifiable-rewards handbook covers the theory and failure modes; this one is the build side — how to design tasks and verifiers that produce a clean, learnable signal in the first place.
How do you filter RL tasks by difficulty?
Sample several attempts per task with the current model and grade them. Park tasks where every attempt fails and retire tasks where every attempt passes, because in both cases all rewards are equal and a group-relative method like GRPO gives every attempt zero advantage. DAPO does this online as dynamic sampling: it over-samples prompts and filters out those with accuracy 1 or 0, so every prompt in a batch carries gradient.
This idea in other formats
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Handbooks
- The Prompting HandbookA friendly, hands-on field guide for everyday humans — learn the CRISP framework, spot bad prompts, practice with real recipes, play a drag-and-drop game, and test yourself with a quiz. No code required.Read →
- The Senior AI Engineer Interview Handbook60 questions across architecture, production incidents, agentic systems, RAG, evals, cost, safety, and leadership — what staff-level AI interviewers actually probe for.Read →
- The LLM Serving HandbookHow to serve large language models fast and cheap — prefill vs decode, the KV cache, continuous batching and PagedAttention (vLLM), quantization, speculative decoding, and the latency-vs-throughput tradeoffs that decide your inference bill.Read →
- The Transformers HandbookThe architecture behind every LLM, built up from scratch — tokens and embeddings, positional encoding, self-attention (query/key/value), multi-head attention, the transformer block (FFN, residuals, layer norm), and how a decoder-only model generates text autoregressively.Read →
- The Fine-Tuning HandbookWhen to fine-tune vs RAG vs prompting, full fine-tuning vs parameter-efficient methods, how LoRA and QLoRA make it cheap enough for a single GPU, why the data matters more than the method, catastrophic forgetting, and how to evaluate and decide.Read →
- The On-Device AI HandbookSmall models, everywhere: why 1–14B models got frontier-adjacent (distillation + textbook data), the napkin law of local inference (tokens/sec ≈ bandwidth ÷ bytes), quantization and the llama.cpp / GGUF / Ollama / MLX stack, the honest local-vs-cloud decision table, four hybrid patterns that ship, and the evals craft of choosing a small model that actually fits the device.Read →