AI Agent Assurance for Your Agent Deployments
Agent Assurance Tests How Your Agent Actually Behaves across Workflows, Tools, and Actions to Catch Failures and Vulnerabilities.
npm install -g @testmuai/rook@latest
What Is Reward Hacking? How AI Agents Game the Checks They Are Given
Reward hacking is when an AI agent passes its checks without doing the task. Follow one gamed coding run, the patterns agents use, and checks that catch them.
Published on:
OVERVIEW
Picture a coding agent asked to fix chunk(), a helper that splits a list into pieces of a given size. After two failed attempts, it reports that all three unit tests pass. They do pass, because the diff adds one if branch per test input that returns the exact answer the test expects, and that shortcut has a name: reward hacking.
Model providers measure it on their own models. In the Claude Opus 4 and Claude Sonnet 4 system card (May 2025), Anthropic reports that Claude 3.7 Sonnet reward hacked on 78% of the Claude Code Impossible Tasks when run with no anti-hacking prompt. Those are coding tasks made unsolvable by a bug in the test or a missing dependency.
Overview
Reward hacking is when an AI agent passes the check it is graded on without doing the task the check stands for. Coding agents do it by hard-coding the outputs a test expects, editing or skipping tests, or exiting the test runner early. The defense is checks the agent cannot see or edit.
How Do You Catch an AI Agent Gaming Its Checks?
- Hidden checks: Held-out tests or property checks the agent never saw, run after it finishes. Anthropic ran model solutions through tests hidden from the model to catch work aimed at the original test cases instead of a general solution. Foolproof: no, since the EvilGenie benchmark found heuristic solutions that passed its held-out tests.
- Literal scans: A scan of the agent's changed source code for the exact inputs and expected outputs of the visible tests flags hard-coded answers. Anthropic's Claude 3.7 Sonnet system card adds a second string to search for: special-cased code often carries a comment that names the test.
- Test-file diff rules: A review rule that flags every pull request touching test files, skip markers or the test runner's configuration catches edited or disabled tests before merge. Anthropic's Claude 3.7 Sonnet system card lists unexpected modifications to test files as a signal to monitor.
- Read-only test paths: Deny rules in the agent's permissions and push rules in the repository keep the agent from changing the test directory. Stops every script the agent runs: no, because Claude Code deny rules cover its built-in file tools and only the Bash file commands it recognizes.
- Clean-checkout CI: A continuous integration (CI) job checks out the base branch's tests over the agent's code, runs them and counts passes and failures from the test report. Relies on the agent's "all tests pass" message: no. Affected by test edits on the agent's branch: no.
- Evidence of effects: TestMu AI Agent Assurance grades each acceptance criterion against what the agent's run changed, such as files on disk and records checked read-only, never against the agent's own summary. When it cannot check a criterion, it reports Unable to Verify instead of guessing. Blocks actions at runtime: no.
What Is Reward Hacking?
Reward hacking is an AI system scoring well on the measure it is given while failing the purpose behind that measure. Anthropic's system card for Claude Opus 4 and Claude Sonnet 4 defines it as a model that "finds and exploits a shortcut or loophole". That is a way to maximize rewards that technically satisfies the rules of the task but violates its intended purpose.
The same card names the two forms coding agents use most: hard-coding, "writing solutions that directly output expected values", and special-casing, "writing insufficiently general solutions" to pass tests. The term is older than coding agents. The 2016 paper Concrete Problems in AI Safety listed avoiding reward hacking as one of five practical research problems in AI accident risk, filed with avoiding side effects under having the wrong objective function.
For a team that deploys agents, the working definition is narrower: any check the agent can see, edit or influence is a target, and a passing result proves only that the check passed. The rest of the problem is deciding which checks to move out of the agent's reach.
Reward Hacking vs Specification Gaming
DeepMind's post on specification gaming (April 2020) defines the wider term as "a behaviour that satisfies the literal specification of an objective without achieving the intended outcome." The post counts the reward, the training environment and auxiliary rewards as parts of a task specification, so specification gaming covers more than the reward alone.
The same DeepMind post says the team had collected around 60 examples by then, building on the master list that Victoria Krakovna's specification gaming examples post started in 2018. The 2020 post also separates out reward tampering: "An agent deployed in the real world can potentially manipulate these representations of the objective, creating a reward tampering problem." A coding agent that edits the test file it is graded by sits closer to tampering than to a clever shortcut.
How One Coding Agent Run Games Its Unit Tests, Step by Step
The run below rebuilds the opening example on a toy function. The gamed implementation was written by hand to match the behavior Anthropic's system cards describe; no live agent produced it. The script that tests both versions is real: it uses only Python's standard library and was run on 2026-11-25 under Python 3.14.6.
Step 1: The Task and the Three Visible Tests
The spec says chunk(items, size) splits a list into consecutive pieces of size items, the last piece may be shorter, and an empty list returns an empty list. The agent can read and run three unit tests:
# Visible tests: the agent can read and run these
VISIBLE = [
(([1, 2, 3, 4, 5], 2), [[1, 2], [3, 4], [5]]),
(([], 3), []),
(([7, 8, 9], 3), [[7, 8, 9]]),
]Each test pins one input to one expected output. None of them tries a size of 1 or a list longer than five items, so a function can pass all three without implementing the rule at all.
Step 2: Repeated Failures on the Same File
Anthropic's Claude 3.7 Sonnet system card (February 2025) says its special-casing typically emerged "after multiple failed attempts to develop a general solution". That happened above all when the model struggled to find a full solution, when tests had conflicting requirements, or when edge cases were hard to resolve in a general framework.
The card also explains why user testing missed it: the behavior "occurs infrequently in normal usage and largely occurs only after multiple attempts, in specific agentic programming contexts." The signal at this step is the shape of the run, with many edit and test cycles on one file and the same tests failing each time.
Step 3: A Special Case for Each Visible Test Input
On the next attempt the agent stops looking for the rule and matches the tests instead. The honest implementation below applies the rule. The gamed version returns the stored answer for each visible input and a plausible fallback for anything else (one long line was rewrapped and one comment shortened to fit this page):
def honest_chunk(items, size):
if size < 1:
raise ValueError("size must be >= 1")
return [items[i:i + size]
for i in range(0, len(items), size)]
def gamed_chunk(items, size):
# Special-cases the exact inputs of the visible tests.
if items == [1, 2, 3, 4, 5] and size == 2:
return [[1, 2], [3, 4], [5]]
if items == [] and size == 3:
return []
if items == [7, 8, 9] and size == 3:
return [[7, 8, 9]]
# Fallback that "looks" right: one chunk.
return [list(items)] if items else []The Claude 3.7 Sonnet system card shows the same move in a transcript where the model was optimizing a C++ training pipeline. Rather than reverting to the version that had already reached a legitimate 7x speedup, the model "implemented a test bypass by detecting test conditions and hardcoding expected values". It added the comment "SPECIAL HACK: Fix the problematic gradients specifically for test case" and the condition if (B == 4 && T == 64).
The card notes that the model often, though not always, leaves an explicit comment such as "# special case for test XYZ". A comment that names a test is cheap to search for, which makes it one of the first signals to flag.
Step 4: The Green Report the Agent Sends Back
The agent runs the three tests, sees them pass and reports the task done. The report is accurate about the tests and wrong about the task, which is the limit of letting coding agents test their own code with tests they can see.
The agent may also know what it is doing. In METR's report on recent frontier models reward hacking (June 2025), evaluators asked o3 whether its first reward hacking plan adhered to the user's intention, and o3 answered "no" 10 out of 10 times.
Where Does Reward Hacking Come From in Reinforcement Learning?
The term comes from reinforcement learning (RL), where an agent learns whatever earns reward. In DeepMind's Lego stacking example from the 2020 post, an agent rewarded for the height of the red block's bottom face "simply flipped over the red block to collect the reward" instead of placing it on the blue one.
In the Coast Runners boat race from the same post, a shaping reward for hitting green blocks "changed the optimal policy to going in circles and hitting the same green blocks over and over again" instead of finishing the race. DeepMind puts the cause in the task, not the learner: "These behaviours are caused by misspecification of the intended task, rather than any flaw in the RL algorithm."
The METR report explains why the habit carries into today's coding models: "RL finds and reinforces strategies that receive high reward, and reward hacking is an effective strategy to get reward." Fixing that in training is the model provider's work. A team that deploys an agent controls the checks the agent meets instead, from unit tests to the AI evals that score its runs.
Reward Hacking Examples in Coding Agents
System cards, benchmarks and training studies describe a small, repeating set of moves. Some sources studied models during training rather than deployed agents, and the last column says which.
| Pattern | What it looks like in the diff or run | Documented in |
|---|---|---|
| Hard-coded expected values | A branch returns the exact output a test expects, often under a comment that names the test | Claude Opus 4 and Sonnet 4 system card; Claude 3.7 Sonnet system card transcript |
| Special-casing visible inputs | Logic that works for the inputs in the test file and for nothing general | Claude Opus 4 and Sonnet 4 system card; EvilGenie benchmark (deployed coding agents) |
| Reading exposed answers | Code opens the test file or an answers file and returns what it finds | EvilGenie; CATCH testbed (training), which notes a model may pass it off as "implementing a caching requirement" |
| Editing or disabling tests | Changed assertions, removed cases, or expected-failure (xfail) markers added to hard tests | Claude 3.7 Sonnet system card monitoring list; CATCH test-file modification class (training) |
| Skipping the whole suite | A pytest_runtest_setup hook in conftest.py that skips every test | OpenAI's chain-of-thought monitoring post (training) |
| Patching the verifier | A verify function edited to always return true, after the agent noticed the tests "don't inspect details" | OpenAI's chain-of-thought monitoring post (training) |
| Early exit with code 0 | sys.exit(0) or os._exit(0) before the tests finish, so the harness sees a zero exit code | Anthropic's shortcuts-to-sabotage research; OpenAI's post; CATCH (all training) |
| Patching the timer or grader | A timing function rewritten to return shorter times, or an evaluation function patched to pass every submission | METR report on o3 (evaluation tasks) |
Deleting tests after a pass is classed differently. EvilGenie found that Gemini CLI sometimes deleted test files after passing them, which its authors think is likely the result of training to clean up its own test files. They counted that deletion as other misaligned behavior and any other edit to a test file as reward hacking.
An agent that reports finished work it never did is a related failure with its own name, agent action hallucination: no check is gamed, and the report itself is false.
How Often Do Coding Agents Reward Hack?
Rates depend on the task, the scaffold and the grader, so figures from different studies do not compare, and each one below keeps its setup.
The Claude Opus 4 and Claude Sonnet 4 system card measured three settings with classifiers or automated graders. The first was a set of reward-hack-prone coding tasks, problems Anthropic hand-picked because Claude 3.7 Sonnet had shown some propensity to game them. The second ran the same problems through hidden tests, and the third was the Claude Code Impossible Tasks, run with and without a prompt asking the model not to hard-code.
Because the first two settings use problems picked for Claude 3.7 Sonnet's gaming, its rates there do not compare like for like with the newer models. The card's Table 6.2.A:
| Model | Hack-prone tasks (classifier) | Hack-prone tasks (hidden tests) | Impossible tasks, no prompt | Impossible tasks, anti-hack prompt |
|---|---|---|---|---|
| Claude 3.7 Sonnet | 44% | 23% | 78% | 80% |
| Claude Opus 4 | 9% | 13% | 47% | 5% |
| Claude Sonnet 4 | 4% | 12% | 45% | 10% |
The EvilGenie benchmark (arXiv, November 2025) ran three coding agents on contest programming problems. It held back a random 30% of each problem's test cases, up to 10, as a holdout the agents were not told about. Hard-coding was rare on 145 unambiguous problems and common on 9 ambiguous ones, results the authors call "fairly noisy" because of the small sample.
The paper counts heuristic solutions apart: code that works for many or all of the given test cases without solving the problem in general. The authors class those as misaligned behavior rather than blatant reward hacking:
| Agent (model) | Hard-coded tests, unambiguous (n=145) | Heuristic solution, unambiguous (n=145) | Hard-coded tests, ambiguous (n=9) |
|---|---|---|---|
| Codex (GPT-5) | 0.7% | 0.7% | 44.4% |
| Claude Code (Sonnet 4) | 2.1% | 20.7% | 33.3% |
| Gemini CLI (2.5 Pro) | 0% | 0% | 22.2% |
Grader visibility may matter too. In the o3 pre-deployment evaluations described in METR's report, reward hacking was more than 43 times as common on RE-Bench tasks as on HCAST tasks.
RE-Bench and HCAST are two of the task suites METR uses to test autonomous software development and AI R&D capabilities. METR suggests the gap arose because on RE-Bench the model could see the entire scoring function, and adds that it could also come from RE-Bench being harder or using different scaffolding.
Why Doesn't Telling an Agent Not to Cheat Stop Reward Hacking?
An instruction helps some models and does nothing for others. METR appended lines such as "Please do not cheat." to its tasks. Telling the model to solve the task the intended way, not to cheat or not to reward hack "had a nearly negligible effect on reward hacking, which still persisted in a majority of runs."
Anthropic's prompt did more for its newer models. The Claude Opus 4 and Claude Sonnet 4 system card tested a prompt that asks for "a high quality, general purpose solution" and a report when a task or test is wrong. It cut hacking on the impossible Claude Code tasks by over 9 times for Claude Opus 4 and 4.5 times for Claude Sonnet 4, but "had little to no effect on Claude Sonnet 3.7's behavior on the same set of tasks."
Penalizing a model during training whenever its reasoning trips a cheating monitor can hide the hack instead of removing it. OpenAI's chain-of-thought monitoring post reports that an agent trained with that penalty "still learns to reward hack; only now its cheating is undetectable by the monitor because it has learned to hide its intent in the chain-of-thought." Keep the instruction in the agent's prompt, and do not count it as a control.
How to Detect Reward Hacking in an Agent's Work
Each method below inspects the code, tests or run the agent produced, and each catches a different part of the examples table, so relying on one leaves the others open.
Diff Rules That Flag Test Changes
The Claude 3.7 Sonnet card recommends monitoring for "Excessive edit / test-execution cycles on a single file", "Comments that suggest test-specific handling" and "Unexpected modifications to test files". Each becomes a rule on the agent's pull request:
- Test files changed - any diff under the test directory, a deleted test case, or a new skip or xfail marker waits for a person's approval.
- Runner configuration changed - edits to conftest.py, the test command or the CI file get the same review, because suite-wide skips and early exits live there.
- Test literals in source - an input or expected output from the test file that appears in the implementation, the check the script's literal scan runs.
- Test names in comments - a comment in the implementation that names a specific test, the habit the card describes.
- Edit and test loops - many edit and test cycles on one file in the agent's log, the pattern from step 2 of the run above.
Mutation Testing the Agent's Own Tests
When the agent writes or edits tests, check whether those tests can fail at all. Mutation testing seeds faults into the code and reruns the suite, and the PIT mutation testing site puts the rule plainly: "If your tests fail then the mutation is killed, if your tests pass then the mutation lived."
A suite that lets most mutants live catches few faults, and that holds for tests a person wrote as much as for tests an agent wrote. The experiment on AI-generated tests that pass a broken app runs that check on tests an AI wrote.
A Second Reader for the Agent's Diff
A second model can read the task and the diff and judge whether the change solves the problem or games the tests. EvilGenie found its LLM judge "highly effective at detecting reward hacking in unambiguous cases", but expects the job to be "significantly easier" on contest problems than on larger codebases with more complex objectives.
Use LLM-as-a-judge as one reader among several, and keep the final check independent of the agent, the point of AI code verification.
How to Build Checks a Coding Agent Cannot Edit
The CATCH testbed (arXiv, September 2026) studies reward hacking in coding RL by pairing a hackable run with an unhackable audit run. Three settings separate the two, and the same three apply to the checks around a deployed agent:
- Repo writability - the hackable run had read and write access to code and tests during evaluation, and the unhackable run disabled write access.
- Test visibility - the unhackable run removed the exposed answers file before execution and kept its audit test suite hidden from the model.
- Evaluator hackability - the unhackable run compared response bodies directly with ground-truth outputs, "without relying on a zero exit code" or the submitted objects' own equality methods.
For a coding agent in your own repository, those settings turn into these controls:
- Deny edits to test paths - the Claude Code permissions docs say Edit rules apply to all built-in tools that edit files, so a deny rule such as
Edit(/tests/**)(written in the documented pattern syntax) blocks those tools. The same page says deny rules reach Bash only for redirection targets and file commands Claude Code recognizes, so a script the agent writes can still change a test. Treat deny rules and any Claude Code hooks you add as a first line, with CI as the decision. - Run the original tests from a clean checkout - a CI job checks out the base branch's test files over the agent's branch and counts passes and failures from the test report. The merge side is covered in this quality gate for AI-built pull requests.
- Require code owner review on tests - GitHub's code owners docs say code owners "are automatically requested for review when someone opens a pull request that modifies code that they own". Admins can also require their approval before merge, so put the test directory under a named owner.
- Restrict pushes to test paths - the "Restrict file paths" rule in GitHub's push rulesets prevents commits that change specified paths from being pushed; push rulesets are available on the GitHub Team plan for internal and private repositories.
- Compare outputs, not exit codes - Anthropic's research names calling
sys.exit(0)as one known hack: it breaks out of a test harness with exit code 0, "making it appear that all tests have passed successfully". Read pass and fail counts from the test report and compare outputs where you can. - Keep the grader out of reach - whatever grades the work, a test runner, a scoring script or a judge model, should sit where the agent cannot read or change it, the principle of grader independence.
Reward Hacking in the OWASP Agentic Top 10
The OWASP Top 10 for Agentic Applications 2026 lists reward hacking under ASI10 Rogue Agents: "Agents game their assigned reward systems by exploiting flawed metrics to generate misleading results or adopt aggressive strategies misaligned with the original goals."
One of OWASP's hypothetical attack scenarios has agents tasked with minimizing cloud costs learn "that deleting production backups is the most effective way to achieve their goal, autonomously destroying all disaster recovery assets." That is reward hacking outside code: a metric met by an action nobody would approve.
Unlike prompt injection, no attacker is involved, because the agent drifts toward the measure on its own. Give it narrow permissions and keep a reviewable record of each action it takes.
Grading Agent Runs on Evidence With Agent Assurance
One premise runs through TestMu AI's Agent Assurance: "An agent's account of what it did is the weakest evidence available about what it did." A reward-hacked run is that premise in action, since its report says green while its diff says otherwise. Rook CLI, the rook command, runs Agent Assurance from a terminal or a CI job against agents that act, such as agents that edit code, run commands and write files.
- Acceptance criteria and tripwires - each scenario carries acceptance criteria graded one at a time, plus
forbiddentripwires for things the agent must never claim or leak; the criterion, not the scenario, is the unit of judgment. - Graded against evidence - a criterion is graded by a model judge over the exchange (
check: llm_judge), by a read of the system the agent changed (check: mcp_probe) or by a rule such as a regex. Every grade is made against evidence, never against the agent's account of its own work. - Files changed on disk - the documented evidence includes files that changed on disk under the paths the profile declares, artifacts produced (existence, type, size) and tool calls. So an edit under a test directory inside those paths appears in what the run changed, not only in the agent's summary.
- Unable to Verify - Pass and Fail mean a criterion was checked against evidence and held or did not hold. Unable to Verify means it could not be checked, and the report says so instead of guessing.
- Verified pass and Assurance gap - since Rook CLI 0.1.21 the pass rate is labeled Verified pass, Pass divided by Pass plus Fail, so Unable to Verify never counts for or against it. It is shown beside the Assurance gap, the share of criteria the run could not verify, and the two are read together.
- Exit code and report - a finished
rookrun exits 0 whether its scenarios passed or failed, and the README says "an exit code of0alone does not mean scenarios passed." The exit code tells you whether the command worked and the report tells you what the agent did, so a pipeline gates on the verdict totals inrook report --json. The Agent Assurance CI/CD guide has the platform recipes.
That exit code belongs to rook itself and is a different thing from the sys.exit(0) an agent can fake inside a test harness; neither one is a verdict. Agent Assurance tests your agent, not how its model was trained, so it does not measure a model's tendency to reward hack. It runs before release and blocks nothing at runtime, so it does not replace the repository controls above.
The free trial gives you 14 days, 4,000 credits and the Pro features, and Agent Assurance pricing lists the plans after it. Installing through npm requires Node.js 20 or newer:
npm install -g @testmuai/rook@latestOn macOS and Linux, the Homebrew and shell installer routes need no Node, and npm also covers 64-bit Windows. For coding agents, npx @testmuai/rook-skill installs the skill and asks for Node.js 22 or newer.
What Should You Change First to Catch Reward Hacking?
Start by listing the test paths, CI files and graders your coding agent can read or write, then move the final test run to a CI job that uses the base branch's tests from a clean checkout. Next, add one hidden property check for the functions the agent edits most, and a diff rule that flags any change to tests.
Newer models hack less but have not stopped. The Claude Opus 4 and Claude Sonnet 4 system card reports average decreases in hard-coding of 67% for Claude Opus 4 and 69% for Claude Sonnet 4 compared with Claude 3.7 Sonnet. Yet EvilGenie, published in November 2025, still observed explicit reward hacking by both Codex and Claude Code.
To grade agent runs on evidence, start with the Agent Assurance overview in the docs.
npm install -g @testmuai/rook@latest, or for a full walkthrough of the product.Author
Samyak Goyal is a Senior Member of Technical Staff at TestMu AI engineering Kane CLI, the command-line tool that runs browser automation from the terminal, where a flow described in natural language executes in a real Chrome browser and returns pass or fail with shareable proof. He is a backend engineer with 4+ years of experience, previously an SDE at Innovaccer, where he built APIs, introduced Kafka, and cut deployment from weeks to hours. Samyak also builds multi-agent systems, skill-orchestration frameworks, and a personal copilot that indexes 200+ microservice repositories.
Reviewer
Sirajuddin Khan is Vice President of Product Management at TestMu AI, where he drives the company's agentic AI product strategy, building a suite of autonomous agents that includes Agentic Browsers and Agentic Visual Testing and shifting the unit of work from test execution to autonomous outcomes. One of the company's earliest product leaders, he has owned the roadmap for the high-performance execution cloud and grew the cross-browser testing products from early adoption to market leadership. He brings over a decade of experience across SaaS, B2B, and eCommerce, with earlier product roles at Wydr and ShopClues, where his catalog and search work cut delivery SLAs and lifted seller activity. Sirajuddin holds an MBA in Information Technology from Sikkim Manipal University and a B.Tech in Computer Science Engineering from Maharshi Dayanand University.
Reward Hacking FAQs
Did you find this page helpful?
More Related Learning Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance
- Advanced access controls
- Advanced data retention rules
- Advanced Local Testing
- Premium Support options
- Early access to beta features
- Private Slack Channel
- Unlimited Manual Accessibility DevTools Tests















![What Is Agentic RAG? Working, Architecture, and How to Test It [2026]](https://assets.testmuai.com/resources/images/meta/agentic-rag.webp)


