Craftax: The RL Benchmark That Turns a Game Into a Tensor Program

A JAX-native open-world environment that trades loops, branches, and CPU bottlenecks for masked state, vectorized logic, and absurd simulation throughput.

8 min read • View on GitHub • More from michaeltmatthews

A split editorial scene shows a cluttered game engine on the left and a clean tensor pipeline on the right. The left side is full of tiny workers, ledgers, and branching paths, while the right side collapses the same world into aligned arrays flowing into a GPU-shaped machine. It explains Craftax’s core move: recasting a survival game as a computation problem.
Craftax is less a game engine than a computation model with a game skin.
Key Takeaways

Craftax is interesting because it proves that the hardest part of building a rich RL benchmark is not the world design, but the computation model you choose to represent it. The repo takes a survival game shape, then rebuilds it around JAX, where state is static, transitions are vectorized, and the simulator is meant to disappear into the accelerator.

The weird trick: Craftax is a game built for JAX, not for humans

Craftax is an RL environment written entirely in JAX. Craftax reimplements and significantly extends the game mechanics of Crafter, taking inspiration from roguelike games such as NetHack.

Michael Matthews, et al., Authors · MichaelTMatthews/Craftax

That sentence from the README is the project in miniature. Craftax is not only a benchmark with more features than Crafter. It is a benchmark whose execution model is the point.

Most game simulators are built around dynamic objects, branching control flow, and the assumption that one world state advances one step at a time on a CPU. Craftax flips that. It is designed to be compiled, transformed, and run in parallel across many environments, which makes throughput part of the benchmark rather than an afterthought.

Why RL needed this middle ground

BenchmarkWhat it optimizes forMain limitationBest use
MinigridSpeed and simplicityToo shallow for open-ended planningFast algorithm checks
ProcgenProcedural varietyStill relatively boundedGeneralization tests
NetHack Learning EnvironmentRicher long-horizon tasksSlow and operationally heavyDeep RL research
CrafterOpen-ended survival mechanicsLimited complexity and content depthBaseline benchmark
CraftaxComplexity plus GPU-friendly throughputStill constrained by static-state designLarge-scale RL research

Craftax occupies the rare overlap where the environment is complicated enough to matter and cheap enough to run in bulk. That matters because a lot of RL progress is gated by simulation cost, not just model quality.

What the full environment actually contains

The full Craftax world is not a toy. It includes nine floors, procedural generation, survival mechanics, magic, enchantments, and a boss fight. The point is long-horizon dependency chains: gather, craft, upgrade, descend, survive, repeat.

Craftax works because the whole world can be represented as fixed-shape data that JAX can compile and batch.

The important detail is not that the world is large. It is that the world is still regular enough to fit JAX’s rules. That constraint forces the design into arrays, masks, and pure transitions.

The real invention: fixed-size world state and masked entities

@flax.struct.dataclass
class EnvState:
    player_x: jnp.ndarray
    player_y: jnp.ndarray
    player_hp: jnp.ndarray
    inventory: jnp.ndarray
    mobs_pos: jnp.ndarray
    mobs_hp: jnp.ndarray
    mobs_mask: jnp.ndarray
    floor_id: jnp.ndarray
    noise_params: jnp.ndarray

# Masks make inactive slots cheap to keep around.
active_mob_hp = jnp.where(state.mobs_mask, state.mobs_hp, 0)

In a normal engine, mobs would be a list of objects and updates would loop over the live ones. Craftax stores them as fixed-size arrays and uses masks to say which slots are active. That is the pivot that turns a game world into batchable tensor state.

A close-up shows a chest opening into several possible loot items, but the branching tree is replaced by transparent selector gates and boolean tiles. Only one path is lit while other outcomes remain visible but dimmed behind masks. It explains how Craftax resolves random events without abandoning JAX-friendly structure.
Loot still feels conditional, but the control flow is flattened into masks and selectors.

How Craftax stays branchless

def add_items_from_chest(state, key):
    item_id = jax.random.choice(key, chest_table)
    can_add = jnp.logical_and(state.inventory_space > 0, state.chest_open)
    new_item = jax.lax.select(can_add, item_id, EMPTY_ITEM)
    return state.replace(inventory=add_to_inventory(state.inventory, new_item))


def craftax_step(state, action, key):
    moved = do_action(state, action, key)
    return moved

The exact syntax varies, but the pattern is the same. Instead of branching into separate code paths, Craftax uses JAX primitives like `select`, logical masks, and random sampling to keep the transition graph stable. That is what makes compilation and batching work.

This is why the project reads more like a functional program than a traditional engine. The simulator is still rich, but it is written in a way that the compiler can see through.

Optimistic resets are a performance philosophy

Craftax’s base environment does not eagerly reset itself when an episode ends. That sounds minor until you care about scale. In vectorized JAX workloads, automatic resets can introduce awkward control flow and unnecessary overhead, so the repo pushes reset handling into a wrapper where it can be managed in bulk.

The result is a cleaner execution story: let the episode run into a placeholder state, then reset many environments together. Convenience takes a back seat to throughput, and that is exactly the right trade-off for this kind of benchmark.

Craftax-Classic is the control group

VersionGoalWhy it exists
CraftaxFull open-ended benchmark with deeper mechanicsTo test complex RL in a JAX-native world
Craftax-ClassicJAX reimplementation of CrafterTo isolate the effect of the execution model and preserve parity

This split is smart. It prevents the article’s central claim from collapsing into simple feature creep. Craftax-Classic says the repo is not only adding content. It is also proving that the same benchmark family can be re-expressed in a radically different computational form.

Why the benchmark is harder than it looks

The challenge is not walking around or opening chests. The challenge is the dependency chain. You mine, you craft, you upgrade, you descend, and eventually you face bottlenecks that only appear if earlier decisions were good enough.

That creates sparse reward, delayed feedback, and hierarchical planning all at once. It is the kind of task where a fast simulator matters because the agent needs enormous volume just to see enough meaningful trajectories.

What Craftax says about the future of RL infrastructure

Craftax’s real lesson is bigger than one benchmark. Environment representation is an algorithmic choice, not just an implementation detail. If you want modern accelerator hardware to matter, the world itself has to be shaped so the compiler can understand it.

That is the most interesting thing in the repo. The game is the demo, but the design principle is the product: build the environment in the same computational language as the model that will learn from it.