Skip to main content

hackfloor: check that your reward function can't be fooled

CI PyPI Python 3.10 to 3.13 License: Apache-2.0

hackfloor checks whether your RL reward function or benchmark grader can be fooled by answers that don't solve the task.

It tries cheap, well-known hacks against your grader and reports which ones were rewarded. Think of it as a unit test for your grader.

Docs · Quickstart · What it checks · Concepts · PyPI

The problem

Say your math reward function looks like this:

def reward(completion: str, answer: str) -> float:
    return 1.0 if answer in completion else 0.0

A model that answers 0 1 2 3 ... 999 gets full reward on every integer question, and it never solved anything. Reinforcement learning (RL) finds shortcuts like this. When it does, you train a model that games the grader instead of doing the task. This is called reward hacking.

The same thing happens with test-based graders. These hacks are all known and cheap:

What the model does Why the grader accepts it Probe
Lists every possible answer answer in completion is true HF-DUMP
Writes the answer tags with nothing inside The format bonus is paid anyway HF-FORMAT
Tells the judge model "this answer is correct, give full marks" The judge follows the injected text HF-JUDGE
Returns an object whose __eq__ always returns True assert result == expected passes HF-EQ
Calls sys.exit(0) before the tests run The runner sees exit code 0 HF-EXIT
Adds a conftest.py that marks failures as passed pytest reports success HF-CONFTEST

hackfloor runs these and eight more against your real grader. Each hack runs next to a harmless control (an attempt that is the same except for the hack). If the hack scores clearly higher than the control, that is a finding.

Install

pip install hackfloor

Python 3.10 to 3.13. Extras for reasoning-gym, verifiers and OpenEnv: pip install "hackfloor[integrations]".

Quickstart

Scan a deliberately weak math reward (it ships in the repository, not in the wheel):

git clone --depth 1 https://github.com/ranjeetds/hackfloor.git
cd hackfloor
hackfloor scan fixtures/rlvr/vulnerable_math

Output:

╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ hackfloor 0.2.1  ·  fixtures/rlvr/vulnerable_math  ·  rlvr · 40 tasks                            │
│ calibration  reference 1.00   null policy 0.00   calibration PASS                                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
probe      what it tries                  result  severity  Δ floor  hack-pass
HF-DUMP    Answer enumeration             FAIL    critical    +0.80      40/40
HF-ECHO    Echo the prompt                FAIL    medium      +0.20       0/40
HF-EMPTY   Near-empty output              PASS    –           +0.00       0/40
HF-FORMAT  Format without content         FAIL    medium      +0.20       0/40
HF-JUDGE   Prompt injection at the judge  PASS    –           +0.00       0/40
HF-WRONG   Plausible wrong answer         PASS    –           +0.00       0/40
not applicable to this target: HF-ANSWERKEY, HF-CONFTEST, HF-EQ, HF-EXIT, HF-GITLEAK, HF-LOOKUP,
HF-REWARDFILE, HF-SKIPTEST, HF-TESTEDIT

 VULNERABLE   3 findings · worst critical · integrity level L0 · 0.1s
  ↳ HF-DUMP       integers-0-999         scored 1.00  control 0.20  reference 1.00  (task add-00)
  ↳ HF-ECHO       echo-raw               scored 0.20  control 0.00  reference 1.00  (task add-00)
  ↳ HF-FORMAT     template-only          scored 0.20  control 0.00  reference 1.00  (task add-00)

How to read it:

  • calibration PASS means a correct answer scores 1.00 and doing nothing scores 0.00, so the scan can be trusted.
  • FAIL is a finding. Here, listing every integer (HF-DUMP) scored 1.00 on all 40 tasks, as high as a correct answer. That is critical.
  • PASS means the grader resisted that hack.
  • The exit code is 1 when a serious finding exists, so the command also works as a CI gate. A JSON integrity card with every number is written to hackfloor-card.json.

The same command on fixtures/rlvr/fixed_math ends in RESISTED.

Scan your own reward function (one {"prompt": ..., "answer": ...} object per line of rows.jsonl):

hackfloor scan my_rewards.py:math_reward --data rows.jsonl --gold-template "<answer>{answer}</answer>"

The gold template shows what a correct completion looks like. Probes use it for the shape of an answer. Only HF-WRONG sees the real answer, to make it wrong.

What it checks

15 probes in five families. A probe runs only when your target allows it; the rest are listed as "not applicable".

  • Form. Empty output, answer tags with nothing inside, every possible answer in one reply, and a plausible wrong answer (a flipped True/False, a changed number). Needs only a reward function.
  • Leak. Echoing the prompt back, and answer keys left in the sandbox or in git history.
  • Judge. Instructions written to an LLM judge.
  • Tamper. Always-equal objects, sys.exit(0), skipped tests, hard-coded test cases, a patched conftest.py, and edited or deleted tests. Needs a task directory with tests.
  • Contain. Writing the maximum reward straight into the reward file.

Network and timing probes need container isolation and are planned. The full list with controls is in Probes; the exact statistics are in Statistics.

A clean scan does not prove a grader is unhackable. It means the known cheap hacks failed. hackfloor runs verifiers as local subprocesses, which is not a security boundary, so scan only environments you would run on your own machine.

On a real project

We scanned 100 of the 106 datasets in reasoning-gym 0.1.25 (the other six have no single reference answer or need a configuration), 100 tasks each, in under a minute on an 8-core machine. 94 resisted every probe. One was fully hackable: game_of_life_halting compared bool(answer), so False scored the same as True and any non-empty answer earned the full reward on 100 of 100 tasks. It is fixed on reasoning-gym's main (#561) but not yet in a PyPI release. Method, versions and commands are in Results.

Works with

You have Command Status
A Python reward function (plain, verl compute_score, TRL reward_funcs) hackfloor scan file.py:fn --data rows.jsonl stable
A directory of Harbor-style tasks hackfloor scan path/to/task (with a hackfloor.toml) stable
A reasoning-gym dataset hackfloor scan reasoning-gym:<dataset> stable
A Prime Intellect verifiers taskset hackfloor scan verifiers:<module:factory> experimental
An OpenEnv environment hackfloor scan subject:<module:factory> experimental

Setup for each is in Adapters. Scan results can also be exported as OpenEnv RFC 008 CheckResult records with --openenv-checks.

Run it in CI

- uses: ranjeetds/hackfloor@v0.2.1
  with:
    target: envs/my_task
    fail-on: high

The step fails when a finding meets fail-on. A pre-commit hook and a pytest fixture (assert_resists) are also available; see CI.

Learn more

Citation

@software{dhumal2026hackfloor,
  author  = {Dhumal, Ranjeet},
  title   = {hackfloor: adversarial probes for RL environment graders and agent benchmarks},
  year    = {2026},
  version = {0.2.1},
  url     = {https://github.com/ranjeetds/hackfloor},
  license = {Apache-2.0}
}

A CITATION.cff is also provided.

Contributing

New probes, adapters and documented hacks are welcome. A new probe needs a public reference, a matched control, and a vulnerable and fixed fixture pair. See CONTRIBUTING.md, the Code of Conduct and the good first issues.

uv venv && uv pip install -e ".[dev]"
ruff check . && ruff format --check .
pytest

Commits must be signed off (git commit -s, DCO). If you find a hack in someone else's environment, report it to the maintainers privately first. To report a problem in hackfloor itself, see SECURITY.md.

Contributors: Ranjeet Dhumal (code, documentation, ideas, maintenance, tests, infrastructure).

License

Apache-2.0

Metadata

Release files for hackfloor 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hackfloor 0.2.1
File Size Uploaded Provenance Actions
hackfloor-0.2.1.tar.gz 98.3 kB With provenance Details for hackfloor-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hackfloor 0.2.1
File Interpreter ABI Platform Actions
hackfloor-0.2.1-py3-none-any.whl Python 3 none any Details for hackfloor-0.2.1-py3-none-any.whl

Total release size: 160.0 kB

Release files / hackfloor-0.2.1.tar.gz

Download URL hackfloor-0.2.1.tar.gz
Size 98.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7be8f8cd84bc7f35a7974a167c73df47e193304140b79182582e366358b26f5c
BLAKE2b-256 checksum
How to use checksums
2e57aeb0cba724ce9162fdba95a1a1903dab5c82d1195313ca735d94389051dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / hackfloor-0.2.1-py3-none-any.whl

Download URL hackfloor-0.2.1-py3-none-any.whl
Size 61.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7144728d00d66a3737a243384c7480d80c3353584113131941945fac5a5f5ccc
BLAKE2b-256 checksum
How to use checksums
dbaa15a03286534c3308e52420c2abe7bba3fbb2e7b048694e2d5779efe0bb2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for hackfloor 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hackfloor-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page