Skip to main content

DeepGym

PyPI CI License: PolyForm Noncommercial

Build RL environments and record agent traces, with rewards that hold up against shortcut answers and infrastructure failures.

DeepGym is a Python library for teams that build gyms and trace datasets, and for researchers who train models on them.

Take the coin-change task in the quickstart below. The answer return -1 passes 3 of its 25 cases, so a verifier that pays partial credit gives it 0.12, and a policy trained on that reward learns to collect it. A policy that can read the verifier's files has a shorter route: print the expected output. Outages do damage too. When a sandbox dies mid-run, the 0 it leaves lands in the group baseline and pushes the policy away from an answer that may have been right.

DeepGym runs each answer in a sandbox, apart from the verifier wherever the task allows, and gives a run no verdict when the infrastructure failed rather than the policy, so that run stays out of training. Before you train, deepgym qa attacks each environment with answers that should earn nothing (empty, stubbed or reward-hacking ones, depending on the task) and fails it if any of them earns reward. The rewards then go to verl, TRL, OpenRLHF, Axolotl or lm-evaluation-harness, and agent episodes are recorded as traces with their provenance.

Quickstart

pip install deepgym

Score a correct and a wrong answer to a built-in task. It runs locally with no account or API key. Linux needs bubblewrap installed:

from deepgym import DeepGym, load_environment

dg = DeepGym(mode='local')
env = load_environment('coin_change')

solution = '''
def coin_change(coins, amount):
    dp = [float('inf')] * (amount + 1)
    dp[0] = 0
    for coin in coins:
        for x in range(coin, amount + 1):
            dp[x] = min(dp[x], dp[x - coin] + 1)
    return dp[amount] if dp[amount] != float('inf') else -1
'''
wrong = 'def coin_change(coins, amount):\n    return -1\n'

batch = dg.run_batch(env, [solution, wrong])
for r in batch.results:
    print(r.score, r.passed, r.has_verdict, r.metrics)
# 1.0 True True {'pass_fraction': 1.0}
# 0.0 False True {'pass_fraction': 0.12}

Built-ins pay 1.0 only when every case passes, so the wrong answer scores 0. The share of cases it passed stays in metrics, and each case's result is in r.cases.

mode='local' runs the answer under sandbox-exec (macOS) or bwrap (Linux) and is for development. Without either, local runs refuse unless you set DEEPGYM_ALLOW_UNSANDBOXED=1. On macOS the answer can still read the environment variables of the shell that started DeepGym, and DeepGym warns, naming the ones that look like keys.

Your own environment starts from a template that already passes every check:

deepgym new word_stats --kind function   # or script, repo-patch, multi-turn
deepgym check word_stats                 # the reference passes, empty and stub answers fail
deepgym qa word_stats                    # determinism, reward-hack attacks, your controls

Or define one in code. The verifier reaches the answer only through the deepgym_solution helpers:

from deepgym import Environment

env = Environment(
    task='Write a function `add(a, b)` that returns the sum of two numbers.',
    verifier_code=(
        'from deepgym_solution import load_solution\n'
        'sol = load_solution(solution_path)\n'
        'return 1.0 if hasattr(sol, "add") and sol.add(2, 3) == 5 else 0.0\n'
    ),
)
result = dg.run(env, model_output='def add(a, b):\n    return a + b\n')
print(result.score)   # 1.0

Training

In training the answers come from a policy you don't trust, so they run in a sandbox provider: Docker, Apple container, Daytona, Modal or E2B. Not every task runs on every provider. Desktop tasks, OSWorld included, need Daytona, and SWE-bench Pro and Terminal-Bench 2.0 need a sandbox with network, such as Daytona. With TRL and Docker:

from datasets import Dataset
from trl import GRPOConfig, GRPOTrainer

from deepgym import DeepGym, load_environment
from deepgym.integrations.trl import make_trl_reward_fn

env = load_environment('coin_change')
reward_fn = make_trl_reward_fn(env, DeepGym(mode='docker'))   # or daytona, modal, e2b

trainer = GRPOTrainer(
    model='Qwen/Qwen2.5-0.5B-Instruct',
    reward_funcs=[reward_fn],
    args=GRPOConfig(output_dir='grpo-coin-change'),
    train_dataset=Dataset.from_list([{'prompt': env.task}] * 64),
)
trainer.train()

The snippet repeats one task to show the wiring. MixedEnvironment puts SWE-bench Pro, Terminal-Bench 2.0 and built-ins behind one reward function and sends each completion to the environment its row's env_name names (TRL). A completion whose sandbox or verifier failed gets None. TRL 1.6+ leaves a completion out of the group's baseline only when every reward function returned None for it, so a format reward added beside this one keeps it in.

verl loads the same scoring from its config, with each dataset row naming its environment (verl_rows(['coin_change', 'two_sum']) writes them). Its v1 trainer drops a sample without a verdict instead of scoring it:

reward:
  custom_reward_function:
    path: pkg://deepgym.integrations.verl
    name: compute_score
    reward_kwargs: {mode: daytona}

The examples cover OpenRLHF, lm-evaluation-harness, multi-turn sessions, computer-use agents, Claude Code and Codex in the sandbox, traces, and benchmark imports.

Why the rewards hold up

flowchart LR
    task["Task"] --> policy["Model<br/>or agent"]
    policy -- "answer" --> sandbox["Sandbox"]
    sandbox --> verifier["Verifier"]
    verifier -- "judged" --> reward["Reward<br/>0 to 1"]
    verifier -- "infra failed" --> noverdict["No verdict,<br/>not trained on"]
    reward --> trainer["Trainer"]
    sandbox -. "each step" .-> trace["Trace"]
  • A single-file answer never runs inside its verifier. Verifiers reach it through the deepgym_solution helpers, which start it in a separate process with no network (as another Linux user in a sandbox provider, under sandbox-exec or bwrap locally) and pass back only plain data, so it can't read the expected outputs, print a fake score or patch the verifier.
  • Repo-patch tasks (SWE-bench Pro, MiMo), Harbor tasks and BigCodeBench run the answer's code next to the tests. There the sandbox, the test-infrastructure guard and a fresh grading sandbox do the isolating, and the reward is only as strong as the tests (importers).
  • Infrastructure failures are not scored. When the provider or network fails, or the sandbox or verifier fails before the answer is in play, dg.run raises, and run_batch, eval and the trainer reward functions return the run without a verdict (has_verdict is false). The trainer integrations keep it out of training where the trainer allows.
  • Failures the policy causes are scored. Failing tests, a malformed patch, a patch that touches test infrastructure, an answer that crashes or hangs the verifier, and a sandbox the agent killed all score 0, and a score printed before a crash is never kept.
  • Masking has a cost: a policy can learn to trigger failures that look like infrastructure and escape the penalty. RewardFunction, the TRL, Axolotl and DAPO reward functions, the OpenRLHF endpoint, the verl agent loops and RubricReward warn when more than 5 in 100 samples get no verdict. verl's compute_score and the lm-eval tasks don't.
  • deepgym qa fails an environment whose reference doesn't score 1.0 on every rerun, or whose empty, stub or reward-hack answers earn anything above float noise. It also runs the controls you ship, mutants of the reference (--mutants) and a pass@k difficulty probe against your model (--model).
  • deepgym qa --approve stores the report with a hash of every file, and deepgym check fails once the folder changes.
  • In a rubric for an LLM judge, an unmet must check or a met fatal check scores the answer 0 whatever else it got right. A judge reply that was refused, cut off or malformed gets no verdict. calibrate measures the judge against expert labels (TPR, TNR, Cohen's kappa) before you rely on it.
  • DeepGym stops every process a CLI agent started before grading, and grades a Harbor task in a fresh sandbox from a copy of its work directory.
  • Batch and eval totals still count a run without a verdict as a failed 0, so an outage can only lower a pass rate, and print the judged-only numbers beside them.

The rules are in the reward contract, the QA gate and rubric-judged rewards.

What ships

Area Included
Environments 31 built-ins: 22 coding, 5 computer-use desktops with 8 seeded variants each, 2 tool-use, 2 cyber (list). Single-turn, multi-turn (one live sandbox per episode, from Python or over HTTP) and computer use (screenshots in, mouse and keyboard out, scored on the state the agent leaves)
Benchmarks SWE-bench Pro, Terminal-Bench 2.0 and any other Harbor dataset, BigCodeBench, HumanEval, MBPP, EvalPlus, MiMo-V2.6-RL code tasks, CyberGym, and 16 OSWorld LibreOffice tasks (importers); MixedEnvironment puts several behind one reward function
Sandboxes Docker, Apple container, Daytona (cloud or self-hosted), Modal and E2B; local for development. Desktop tasks need Daytona (sandboxes)
Agents Claude Code and Codex CLI inside the sandbox, Anthropic and OpenAI computer-use and API tool agents, with turn, time and cost budgets (agents)
Training and eval verl (reward function and agent loops), TRL, OpenRLHF, Axolotl, lm-evaluation-harness, RewardFunction for your own loop, and a Gymnasium-style reset/step API
Authoring deepgym new, check and qa, controls, mutation testing and approvals (authoring, verifiers); Hugging Face Hub sharing
Traces Recorded with provenance, token usage and cost; exported as JSONL, Parquet rows for verl and TRL, or ATIF; two runs compared task by task with pass@k and a significance test; scanners for behaviour the verifier missed; versioned datasets with a manifest hash (traces)
Review Labels on runs, episodes, traces and single steps; review queues for expert reviewers, blind by default; judge calibration from stored labels (console)
Serving deepgym serve, an HTTP API with jobs and live sessions (API server); deepgym console, a local web console for environments, runs, episode replay, sandboxes and QA reports (console)

Install

Python 3.10 or later. Optional extras:

Extra Adds
deepgym[daytona], deepgym[modal], deepgym[e2b] Those sandbox providers
deepgym[server] deepgym serve and deepgym console
deepgym[hf] Hugging Face Hub sharing and dataset loaders
deepgym[lm_eval] lm-evaluation-harness tasks
deepgym[traces] Parquet trace export
deepgym[anthropic], deepgym[openai] The built-in computer-use and API tool agents; [anthropic] also the Anthropic rubric judge
deepgym[all] Everything above except lm_eval and the agent extras

Documentation

For teams and labs

DeepGym is free for personal, research and other noncommercial use. Commercial use, including inside a company or in a product you sell, needs a commercial license. We also build private environments and verifiers for your tasks, deploy DeepGym privately or self-hosted, and help set up and run RL training. For DeepGym Pro access or a custom RL environment, email contact@deepgym.io or visit deepgym.io.

Contributing

New environments, verifiers, benchmark importers and integrations are all welcome. Start with a good first issue and see CONTRIBUTING.md for setup, tests and releases.

License

PolyForm Noncommercial License 1.0.0. Commercial use needs a license: contact@deepgym.io.

Metadata

Release files for deepgym 0.6.10

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

Source distribution (sdist)

Source distribution for deepgym 0.6.10
File Size Uploaded Provenance Actions
deepgym-0.6.10.tar.gz 2.4 MB Without provenance Details for deepgym-0.6.10.tar.gz

Built distribution (wheel)

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

Total release size: 4.4 MB

Release files / deepgym-0.6.10.tar.gz

Download URL deepgym-0.6.10.tar.gz
Size 2.4 MB
Tags Source
SHA-256 checksum
How to use checksums
a027bdadafaa52959a574fccf9e2a6d30359f0bb25de16ee16de2717e2146139
BLAKE2b-256 checksum
How to use checksums
0a7598d59cf6ecebf4d344fa0a6e2a0fb4aa4165f085d0bbb394f2e6c150dbd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / deepgym-0.6.10-py3-none-any.whl

Download URL deepgym-0.6.10-py3-none-any.whl
Size 2.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
af874125b8d19f05088493d34fdb8ade14b138022f2cca6250aee7109cbaf75b
BLAKE2b-256 checksum
How to use checksums
b4684c187d422f86c0e20185d51de39e4ce7779045fa1d6f8d997a5e0787c874
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Security for deepgym 0.6.10

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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