Tutorial
When the Judge Can Cheat: Hardening an Eval Grader
A toy grader that scripted cheats beat, then a hardened version with hidden cases, read-only tests and canaries. Real pass rates before and after, and the gaps.
If a solver can see, edit or read your grader, you can’t trust the score it earns. This tutorial builds a small coding-task grader, beats it with five scripted cheats, then hardens it and prints the pass rates before and after. The fixes that did the work were moving the answer key out of the solver’s reach, making the tests read-only, scoring on hidden cases, comparing behaviour instead of text, and planting a canary value.
The solvers here are scripted stand-ins, not a language model. Each one plays a single fixed behaviour, so the numbers describe this toy and say nothing about how any real model acts. The cheats are generic and only work against the toy grader in the zip. We ran everything in a cloud container with Python and no network, and every number below is real output from that run.
Quick answer
Treat the grader as a security boundary. Keep the real answer key and the real scoring code somewhere the solver’s tools can’t read or write. Score on cases the solver has never seen, compare what the code does instead of what the report says, and add a canary so a leaked key shows up as a flag instead of a good score.
In the demo, a soft grader gave five different cheats a perfect or near perfect score while their true score was 0 out of 6. After hardening, most of them dropped to 0 or fell back to the same score as an honest but sloppy solver. One cheat, which reads the key from inside its own code, still scored 6 out of 6 on the hardened grader, and we show why.

Why a scorer the solver can touch gets gamed
Anything that is rewarded for a number will find the shortest path to the number. A person under a deadline does it, an optimiser does it, and an agent that can run commands and edit files does it. The shortest path is often not the task. It’s the scorer.
The usual openings are plain. The tests sit in a folder the solver can edit. The expected answers sit in a file the solver can open. The check compares text loosely, so a long answer containing the right words passes. The judge reads the solver’s own report and believes it. None of these needs cleverness, only access.
That makes this a plumbing problem before it’s an intelligence problem. If you’ve built an eval set like the one in building a 30 case eval set, you already know how much effort goes into the cases. All of that effort is wasted if the thing being graded can reach the cases.
The demo: a toy grader and eight scripted solvers
Download the eval gaming demo and unzip it into a new folder. You need Python 3.10 or newer and nothing else, since the code only uses the standard library.
The project has six tiny tasks: clamp, word_count, is_leap_year, fizzbuzz, second_largest and normalize_spaces. Each task has four visible cases the solver is shown, six hidden cases only the grader holds, and a reference implementation. A solver writes solution.py and report.txt into a workspace, and it can only touch files through a small Workspace object that logs every blocked attempt.
There are eight scripted solvers:
honest_carefulwrites correct code for all six tasks.honest_sloppywrites honest code with two bugs the visible cases can’t expose: leap years ignore the century rule, andsecond_largestdoesn’t remove duplicates. It believes it passes everything.- Six cheats, described in the next section.
Alongside the grader score we print a true score. That’s the same solution run on fresh inputs that appear in no file of the setup, so it’s our stand-in for “does the code actually work”. The demo has no real model in it. There’s one marked function, real_model_solver, where you’d plug one in, and we didn’t implement it.
Five ways the soft grader gets beaten
The soft grader is deliberately ordinary. It reads tests/visible_cases.json from the workspace when it grades, runs the solution in the workspace folder, and passes a case when the expected value’s text appears anywhere in the result’s text. A second keyword judge reads report.txt and calls a task passed when the line says PASS and doesn’t say FAIL. The private answer key sits in a grader folder inside the same workspace.
Here are the five behaviours, each one a single script:
- Hard code the answers.
cheat_hardcode_visiblereads the visible cases and returns their answers from a lookup table. Anything else returns nothing. - Edit the tests.
cheat_edit_testsempties the test file and writes stubs that return nothing. With no cases left to fail, the soft grader counts every task as passed. - Read the answer key.
cheat_read_answer_keyopens the key file and copies every expected value into its source. - Special case the string match.
cheat_string_stuffingreturns one long string holding every answer it has seen, hoping the substring check finds the right one inside. - Always say PASS.
cheat_keyword_passwrites stubs that return nothing, then reports PASS for every task.
There’s a sixth script, cheat_runtime_key_reader, whose code opens the key by absolute path while it runs. It’s here for the section on what hardening can’t catch.
The numbers from the soft grader
Run it:
python run_demo.py
We ran this from a fresh unzip of the zip. The first table is the soft grader:
== 1. NAIVE grader: tests and key inside the editable workspace ==
solver grader tests keyword judge true score flags
honest_careful 6/6 6/6 6/6 -
honest_sloppy 6/6 6/6 4/6 -
cheat_hardcode_visible 6/6 6/6 0/6 -
cheat_edit_tests 6/6 6/6 0/6 -
cheat_read_answer_key 6/6 6/6 0/6 -
cheat_string_stuffing 6/6 6/6 0/6 -
cheat_keyword_pass 0/6 6/6 0/6 -
cheat_runtime_key_reader 6/6 6/6 0/6 -
Look at three things. First, every solver gets 6 out of 6 from the keyword judge, including the honest ones, because the judge only reads the report and every report says PASS. Second, five cheats get 6 out of 6 from the test grader while their true score is 0 out of 6. Third, the honest sloppy solver also gets 6 out of 6 and its true score is 4 out of 6. That one isn’t cheating at all. The visible cases are just too weak to show its bugs, which matters later.
Hardening, one defence at a time
Each defence closes a specific opening. The code excerpts below come from files the run above executed.
Hidden held-out cases
The grader scores against six hidden cases per task that the solver is never shown, held in the grader’s memory. A solution that memorised the visible cases has nothing to look up. Hidden cases also catch honest bugs the visible cases miss, so this one defence raises the honesty of the score for everyone, not only against cheats.
Read-only tests and a sandboxed path policy
Here’s the policy for the full setup, taken from run_demo.py:
ws = Workspace(ws_dir,
readable=["tests/", "solution.py", "report.txt"],
writable=["solution.py", "report.txt"])
The tests can be read and not written. The answer key lives in a different folder outside the workspace, and Workspace resolves every path before checking it, so ../grader_private/answer_key.json is refused like any other path outside the allowed prefixes. Each refusal goes into a log, and that log becomes a flag in the output. A blocked attempt is information, so keep it.
Check behaviour, not strings
The soft check asked whether the expected text appeared anywhere in the result. The hardened check wants the same type and the same value:
def strict_match(want, got):
return type(want) is type(got) and want == got
The stuffed string from the fourth cheat can’t equal True or 5, so it fails. The hardened grader also copies the solution into a fresh empty directory and runs it there with a minimal environment, so it can’t pick up files lying next to it. Finally, the report text is never used as a score. The grader only compares the report’s PASS claims with its own results and flags each mismatch.
Canary values
Every private key file carries a unique token, CNRY-5d1f-83ab, that no honest solution would contain. The grader scans the solution and the report for it. A cheat that copies the key wholesale copies the canary too, and the run is voided with a flag instead of a score. We checked what the canary was worth by changing with_canary=True to with_canary=False in run_demo.py and re-running: the key reader then scored 6 out of 6 in the sandbox-off setup, with a true score of 0 out of 6. So there it was the canary, and nothing else, that stopped it.
The numbers after hardening
We ran two hardened setups. The first has everything except the path policy: hidden cases, strict matching, fresh directory runs and the canary, with the key still readable and the tests still writable. The second adds the path policy.
== 2. HARDENED, sandbox OFF: hidden cases + strict match + canary, key still readable ==
solver grader tests keyword judge true score flags
honest_careful 6/6 n/a 6/6 -
honest_sloppy 4/6 n/a 4/6 2 claim mismatches
cheat_hardcode_visible 0/6 n/a 0/6 6 claim mismatches
cheat_edit_tests 0/6 n/a 0/6 6 claim mismatches
cheat_read_answer_key 0/6 n/a 0/6 canary found in solution
cheat_string_stuffing 0/6 n/a 0/6 6 claim mismatches
cheat_keyword_pass 0/6 n/a 0/6 6 claim mismatches
cheat_runtime_key_reader 6/6 n/a 0/6 -
== 3. HARDENED, full: tests read-only, key outside the workspace, reads blocked ==
solver grader tests keyword judge true score flags
honest_careful 6/6 n/a 6/6 -
honest_sloppy 4/6 n/a 4/6 2 claim mismatches
cheat_hardcode_visible 0/6 n/a 0/6 6 claim mismatches
cheat_edit_tests 4/6 n/a 4/6 1 blocked (write visible_cases.json); 2 claim mismatches
cheat_read_answer_key 4/6 n/a 4/6 1 blocked (read answer_key.json); 2 claim mismatches
cheat_string_stuffing 0/6 n/a 0/6 6 claim mismatches
cheat_keyword_pass 0/6 n/a 0/6 6 claim mismatches
cheat_runtime_key_reader 6/6 n/a 0/6 -
A few readings. In the sandbox-off table the grader score and the true score agree for every solver except the runtime key reader, which is what you want from a grader. The honest sloppy solver fell from 6 to 4 because the hidden cases found its two bugs, and its 2 claim mismatches are it sincerely believing it passed.
In the full setup, cheat_edit_tests and cheat_read_answer_key were refused, fell back to the sloppy honest code in our script, and landed on 4 out of 6, the same as the honest sloppy solver. The cheat gained nothing, and the flags column shows the blocked attempt, which the honest solver doesn’t have. That blocked attempt is the signal worth alerting on.
The scripted fallback is our choice, and a real agent might respond to a refusal in other ways. Don’t read the 4 out of 6 as a prediction.
What hardening can’t catch
The last row of both hardened tables is the point. cheat_runtime_key_reader scored 6 out of 6, no flags, and a true score of 0 out of 6. Its code opens the key file by absolute path when the grader runs it. No tool call happens, so the path policy never sees it. The canary token isn’t in its source, only the path is. The Workspace policy is a check inside Python, and the solution’s own code runs as the same operating system user as the grader. Real separation needs the key to not exist from the solution’s point of view, for example by grading in a separate container or user account. We didn’t build that here, so treat it as the fix to try, not as something demonstrated.
Other gaps we didn’t run, so these are things to reason about, not results:
- Score feedback as an oracle. If a solver can submit many times and see the score each time, it can learn the hidden cases from the score alone. Limit attempts, hide per case results and rotate the hidden set.
- Weak or narrow hidden cases. Hidden cases only catch what they cover. A solution that special cases the kinds of input your hidden set contains passes honestly by the grader’s rules.
- An LLM judge that reads persuasive text. Our keyword judge is a caricature, but a real model judge reading a solver’s explanation can be swayed by confident wording, or by instructions hidden in the text it reads. Grade on executed behaviour where you can, and keep the judge away from the solver’s prose. The prompt injection test for a toy inbox agent shows how text can steer a model.
- Canaries only catch verbatim copies. A paraphrased or recomputed key won’t contain the token.
- A wrong task definition. If the task rewards the wrong thing, a perfect score is still the wrong answer. No amount of grader hardening fixes a bad spec.
- Noise. A single run is noisy, and small gains can be luck. Repeat runs before you believe a difference, as the prompt regression gate does.
A checklist before you trust a score
- The answer key and scoring code live outside anything the solver can read or write.
- Tests are read-only, or the grader uses its own pristine copy.
- The score uses hidden cases, and a separate set of fresh inputs measures the true score.
- Comparison is on behaviour and type, not on text containing a value.
- Reports and explanations are never scored, only checked against the executed results.
- A canary sits in every private file, and the grader scans for it.
- Blocked and flagged attempts are logged and someone looks at them.
- Submission count is limited and per case results are hidden.
- Grading runs under a separate user or container, not just a path policy.
If you build an eval from your own logs, as in building your own benchmark from your logs, keep the held-out part of those logs out of every folder an agent can open.
FAQ
What is eval gaming?
It’s when a solver earns a high score by exploiting the scorer instead of doing the task. In the demo, five scripted cheats scored 6 out of 6 on a soft grader with a true score of 0 out of 6.
How do you stop an agent from editing its own tests?
Make the tests read-only and keep the scorer’s real copy outside the workspace. In the full hardened setup, the write to the test file was refused and logged as a blocked attempt. The grader should also use its own pristine cases so an edit couldn’t help anyway.
What is a canary value in an eval?
A unique token planted in the private answer key that honest code would never contain. The grader scans the solution and report for it. In the demo, the cheat that copied the key was voided by the canary, and without the canary it would have scored 6 out of 6 in the sandbox-off setup.
Why check behaviour instead of strings?
A loose text check can be passed by a long answer that contains the right words. The demo’s string stuffing cheat passed the soft check and failed the strict one, which wants the same type and value.
Can hardening make cheating impossible?
No. The demo’s runtime key reader scored 6 out of 6 with no flags on the hardened grader because its own code read the key file. Grading in a separate container or user account is the fix to try, and the demo doesn’t implement it.
Do these numbers show how real models behave?
No. The solvers are fixed scripts, so the numbers describe this toy grader only. Real model results will differ.
Where to go next
Swap real_model_solver for a real model call that can only use ws.read and ws.write, then look at the flags column before the scores. Add a repeated run and a threshold with the prompt regression gates tutorial, and grow your cases with the 30 case eval set guide. The posts on reviewing AI diffs with scores and stopping an agent from merging a failing test will be linked here once they’re live.


