Skip to main content

NetHack Gym environment

Full NetHack 3.6.0 from the pinned NetHackDS fork, with its original tiles, controller-driven name/character selection, menus, and a desktop renderer. This package builds and runs independently of fmri-gym. No Nintendo SDK, emulator, ROM, flex, or bison is required.

Install and play

Use Python 3.10–3.13 on Linux or macOS. Native compilation requires cc and make (on macOS, install the Xcode command line tools). Windows builds are not provided. Linux/macOS are intended targets; validate your actual machine.

From a source checkout:

git submodule update --init --recursive
python -m pip install .
nethack-gym-build
nethack-gym

A built wheel includes the pinned engine sources, fonts, tiles, license, and build tools. Wheel users do not need Git or a separate engine checkout:

python -m pip install /path/to/nethack_gym-0.1.0-py3-none-any.whl
nethack-gym-build
nethack-gym

A wheel contains source, not a precompiled engine. The explicit build step is still necessary. Installing or resetting the environment never downloads or compiles anything. nethack-gym-build --source /path/to/nethackds overrides the bundled source; patches require the compatible fork/version.

The default build cache is ~/.cache/nethack-gym/3.6.0-desktop-4-cursor. NETHACK_GYM_HOME overrides it; use a path without whitespace because of upstream Makefile restrictions. The old fmri-gym cache is not migrated. To reuse an old runtime/native saves, explicitly set that variable to its old revision directory; retain backups. Rebuild when runtime compatibility requires it.

Gymnasium API

import gymnasium as gym
import nethack_gym  # registers the environment

env = gym.make("NetHackGym-v0", game_mode="classic")
try:
    observation, info = env.reset(seed=1000)
    observation, reward, terminated, truncated, info = env.step(5)
    pixels = env.render()
finally:
    env.close()

render_mode="rgb_array" is the supported render mode. runtime= can select a previously built runtime directory. Actions are integers 0–7: Up, Right, Down, Left, Z/A, X/B, C/X, V/Y. Observations contain tiles, glyphs, and 1280×720 RGB pixels. Reward is currently zero. The native game determines termination.

Play and campaigns

The standalone player uses arrows and Z/X/C/V, or an SDL game controller. Z confirms, X cancels or searches, C opens commands/the keyboard, and V opens inventory. Escape closes the window. Select letters and Enter using the on-screen keyboard to name a character. Menus and role/race/gender/alignment selection are provided by the actual engine.

nethack-gym --mode classic
nethack-gym --mode modern
nethack-gym --campaign player-001.campaign --seed 1000

The standalone player defaults to Modern mode; the Gymnasium environment defaults to Classic. Classic retains permadeath. Modern adapts GnollHack's revival/healing and score divisor, with this port's floor-entry respawn checkpoints and brief protection. It is not the full GnollHack engine or content.

Without a seed or campaign file, standalone play uses native saves under player-classic or player-modern in the cache. Re-enter the character name to restore. With --campaign, use the same file and mode to continue later. Campaigns use seed/action replay, not a portable native save snapshot. Engine, mode, and frontend fingerprints must match. Moving to this standalone replay implementation changes the fingerprint; previous checkpoints are rejected rather than silently replayed with different code. Keep old environments for old checkpoints. Native save compatibility is separately architecture/version specific and is not guaranteed by matching filenames.

Only load campaign/checkpoint files from trusted sources. They use Python pickle. This package owns its replay implementation and has no dependency on fmri-gym or replay-state-gym.

Build package distributions

git submodule update --init --recursive
python -m pip install build
python -m build

Both the source archive and wheel must contain the populated engine tree. Building from an sdist does not require initializing submodules. The source .gitmodules entry documents the upstream dependency; it does not cause pip to fetch missing source files. See _vendor/PROVENANCE.json within the Python package for the pinned engine commit. Never edit the engine submodule directly for local patches: build.py patches a disposable copy in the cache.

Tests

python -m pip install '.[test]'
nethack-gym-build
nethack-gym-build --test-driver --home /tmp/nethack-gym-tests
export NETHACK_GYM_TEST_HOME=/tmp/nethack-gym-tests
python -m pytest

The production and test-driver builds are separate. Test-driver engines are rejected by normal clients. Native tests can also run without Gymnasium/pygame (using numpy and Pillow):

python -m unittest discover -s tests -p test_native.py -v
python -m unittest discover -s tests -p test_modern_engine.py -v
python -m unittest discover -s tests -p test_entry_recovery.py -v

Optional fmri-gym integration

fmri-gym should install this package as an external dependency and retain its adapter, scanner/rig configuration, curricula, recording, and integration tests. It should not be required to supply NetHack source. The original integration notes are preserved in docs/fmri-gym-integration.md. The nethack-campaign command can export a compatible recorded block into an fmri-gym curriculum; it only reads/writes JSON and requires no fmri-gym import. Integration tests are retained separately in integration_tests/ pending migration to the consuming repository.

Source and notices

See LICENSE and nethack_gym/THIRD_PARTY.md. The engine's 820 upstream files are unchanged. Desktop patches and the optional Modern adaptation are applied during the native build. Supplied GnollHack reference files are included with their original license/provenance but are not compiled. No blanket license-compliance assessment of another application is implied by this package extraction.

Metadata

Release files for nethack-gym 0.1.0

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

Source distribution (sdist)

Source distribution for nethack-gym 0.1.0
File Size Uploaded Provenance Actions
nethack_gym-0.1.0.tar.gz 4.7 MB Without provenance Details for nethack_gym-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nethack-gym 0.1.0
File Interpreter ABI Platform Actions
nethack_gym-0.1.0-py3-none-any.whl Python 3 none any Details for nethack_gym-0.1.0-py3-none-any.whl

Total release size: 9.8 MB

Release files / nethack_gym-0.1.0.tar.gz

Download URL nethack_gym-0.1.0.tar.gz
Size 4.7 MB
Tags Source
SHA-256 checksum
How to use checksums
26425f959701a1915f08fc2d4121bee39ef4bb7d1b98a9df9749c18cdb7a14c6
BLAKE2b-256 checksum
How to use checksums
7452c1bb14e148dd5b436b17f8f505c00a25a1ddc3809b8aab279815edde7f67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / nethack_gym-0.1.0-py3-none-any.whl

Download URL nethack_gym-0.1.0-py3-none-any.whl
Size 5.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
44f69cc621fe6d75f95852526f3e8b69ba12e3e5fe042388f056e6eaef33c7c3
BLAKE2b-256 checksum
How to use checksums
d4783115ad10f76a07ce586a13a97cbe59ed5447cb86a9526ffff1d6827cac89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for nethack-gym 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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