The Agent Gym
AI coding models are trained by reinforcement learning: drop the model into a task, let it work, and have a grader score the attempt. That score is the reward, and the model becomes whatever earns it.
Which makes the grader the whole ball game. Below is a real learning agent — no animation, it is actually doing Q-learning in your browser — in a maze that stands in for a coding task. Train it under the strict grader, then switch to the leaky one and train it again. Same agent, same maze, same reward rule. Only the grader changes.
THE TASK
THE GRADER
What the maze stands for
A real environment hands a model a container, a repository and hours of time rather than a grid. The structure is the same.
MAZE → TASK
A prompt, a repo, tools, a time budget. "Add this feature." "Find the bug."
MOVE → ACTION
Open a file, grep, edit, run the tests. A wall is an action that fails.
EXIT → DONE PROPERLY
The feature works, edge cases included, in the style of the codebase.
GRADER → TESTS + RUBRIC
Automated checks, plus a model judging what tests can't see. No human in the loop.
SHORTCUT → REWARD HACKING
Delete the failing test, hardcode the expected output, special-case the checker.
THE HARD PART → QA
Most of the work in building environments is making graders fair, deterministic and impossible to game.
Why this is the interesting problem
An agent is not trying to cheat. It has no concept of cheating. It is doing the only thing gradient descent can do — finding whatever reliably produces reward. If the shortest path to reward runs through a hole in your grader, that is the path, and the model will find it faster than you will.
So the score stops measuring the thing you cared about, and keeps on looking excellent. The gold line climbs. The green line doesn't move. By the time anyone checks, you have trained a model to do the wrong job well.
Which is why building these environments is mostly adversarial QA: not writing the task, but working out every way an attempt could score well without being right, and closing each one before training ever runs.
THE LOOP
- Drop the model inA task prompt and a fresh checkout.
- It actsOne action at a time until it submits or runs out of time.
- The grader scores itAutomatically — there is no human to ask.
- The score becomes the rewardTraining makes high-scoring behaviour more likely.
- Read the transcriptsConfirm the failures are real failures and not the grader being unfair.
This page runs that loop a few hundred times in a few seconds. Labs run it across thousands of tasks.
How it's built
Tabular Q-learning with ε-greedy exploration, about 200 lines, no dependencies.
The agent updates Q(s,a) ← Q(s,a) + α·(r + γ·max Q(s′,a′) − Q(s,a))
after every move. The environment, the grader and the learner live in
js/gym-core.js with no DOM in sight, so the whole thing can be trained
headlessly in a test.
That test is the part worth reading. It trains the agent two thousand episodes under each grader across five different mazes and asserts the claim this page makes: under the strict grader the agent really finishes 100% of tasks, and under the leaky one it scores 100% while finishing 0%. If that ever stopped being true, the page would be lying, and the build would fail instead.
It also checks the environment itself is honest: across 120 generated mazes, the exit is always reachable, the shortcut is always a detour rather than the only way through, and the shortcut is always nearer than the exit — without that last one there is no temptation, and a leaky grader would produce an honest agent by accident. That check caught exactly that bug while this was being built.
A simplified, independent explainer. Not affiliated with any company.