Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Farama Foundation Gymnasium Env Registry Init

From Leeroopedia
Knowledge Sources
Domains Reinforcement_Learning, Environment_Registry
Last Updated 2026-02-15 03:00 GMT

Overview

The environment registry initialization module that registers all built-in Gymnasium environments and exposes the make, register, registry, spec, and pprint_registry functions.

Description

The envs/__init__.py module serves as the central registry for all built-in Gymnasium environments. On import, it executes register() calls for each environment, defining the environment ID, entry point (module path and class name), and optional parameters such as max_episode_steps, reward_threshold, kwargs, vector_entry_point, and disable_env_checker.

The registered environment categories are:

Classic Control (6 environments): CartPole-v0/v1, MountainCar-v0, MountainCarContinuous-v0, Pendulum-v1, Acrobot-v1. CartPole includes vector entry points for optimized vectorized execution.

Phys2D / JAX Classic Control (3 environments): phys2d/CartPole-v0/v1, phys2d/Pendulum-v0. These are JAX-accelerated versions with both single and vector entry points, with env checker disabled.

Box2D (5 environments): LunarLander-v3, LunarLanderContinuous-v3, BipedalWalker-v3, BipedalWalkerHardcore-v3, CarRacing-v3.

Toy Text (6 environments): Blackjack-v1, FrozenLake-v1, FrozenLake8x8-v1, CliffWalking-v1, CliffWalkingSlippery-v1, Taxi-v3.

Tabular / JAX Tabular (2 environments): tabular/Blackjack-v0, tabular/CliffWalking-v0. JAX-based functional implementations with env checker disabled.

MuJoCo (many environments): Includes v2 (deprecated, raises ImportError pointing to gymnasium-robotics), v4, and v5 versions of Reacher, Pusher, InvertedPendulum, InvertedDoublePendulum, HalfCheetah, Hopper, Swimmer, Walker2d, Ant, Humanoid, and HumanoidStandup.

Shimmy Compatibility (2 environments): GymV21Environment-v0 and GymV26Environment-v0, which raise ImportError until shimmy is installed.

Usage

This module is automatically imported when import gymnasium is executed. Users interact with the registry via gymnasium.make("EnvId-vN"), gymnasium.register(), and gymnasium.pprint_registry().

Code Reference

Source Location

Signature

from gymnasium.envs.registration import make, pprint_registry, register, registry, spec

# Example registration call
register(
    id="CartPole-v1",
    entry_point="gymnasium.envs.classic_control.cartpole:CartPoleEnv",
    vector_entry_point="gymnasium.envs.classic_control.cartpole:CartPoleVectorEnv",
    max_episode_steps=500,
    reward_threshold=475.0,
)

Import

import gymnasium as gym

# All registry functions are available at the top level
env = gym.make("CartPole-v1")
gym.pprint_registry()
spec = gym.spec("CartPole-v1")

I/O Contract

Inputs

Name Type Required Description
id str Yes Environment identifier (e.g., "CartPole-v1", "phys2d/CartPole-v0")
entry_point str or Callable Yes Module path and class name or callable that creates the env
vector_entry_point str or None No Module path for an optimized vector environment class
max_episode_steps int or None No Maximum steps before truncation (wraps with TimeLimit)
reward_threshold float or None No Reward threshold for "solving" the environment
kwargs dict or None No Default keyword arguments passed to the environment constructor
disable_env_checker bool No Whether to skip the passive env checker wrapper

Outputs

Name Type Description
env gymnasium.Env The instantiated environment (from make())
spec EnvSpec The environment specification (from spec())

Usage Examples

import gymnasium as gym

# Create an environment
env = gym.make("CartPole-v1", render_mode="rgb_array")

# Create a JAX-accelerated environment
jax_env = gym.make("phys2d/CartPole-v1")

# Register a custom environment
gym.register(
    id="MyCustomEnv-v0",
    entry_point="my_module:MyCustomEnv",
    max_episode_steps=1000,
)

# List all registered environments
gym.pprint_registry()

# Get spec for an environment
spec = gym.spec("Taxi-v3")
print(f"Max steps: {spec.max_episode_steps}")
print(f"Reward threshold: {spec.reward_threshold}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment