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 Passive Env Checker

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

Overview

A collection of passive checker functions that validate Gymnasium environment implementations without modifying their behavior.

Description

The passive_env_checker module provides a suite of non-intrusive validation functions that inspect environment spaces, observations, rewards, and render outputs for correctness. It checks that observation and action spaces are properly defined (e.g., Box shapes are consistent, Discrete spaces have positive element counts), that observations returned by reset() and step() conform to declared observation spaces, that rewards are valid numeric types (not NaN or Inf), and that render outputs match the declared render mode (e.g., rgb_array returns a uint8 numpy array with 3 channels). Warnings are issued through the Gymnasium logger rather than raising exceptions, allowing environments to continue operating while surfacing potential issues.

The module exposes five primary public functions via __all__: env_render_passive_checker, env_reset_passive_checker, env_step_passive_checker, check_action_space, and check_observation_space. The space checkers are constructed as functools.partial wrappers around a shared check_space function, which recursively validates nested Tuple and Dict spaces.

Usage

Use these functions when developing custom Gymnasium environments to validate that spaces, observations, rewards, and render outputs are correctly implemented. They are also used internally by the Gymnasium PassiveEnvChecker wrapper which wraps environments automatically during gymnasium.make().

Code Reference

Source Location

Signature

def check_space(space: Space, space_type: str, check_box_space_fn: Callable[[spaces.Box], None]) -> None

check_observation_space = partial(check_space, space_type="observation", check_box_space_fn=_check_box_observation_space)
check_action_space = partial(check_space, space_type="action", check_box_space_fn=_check_box_action_space)

def check_obs(obs, observation_space: spaces.Space, method_name: str) -> None

def env_reset_passive_checker(env, **kwargs) -> tuple
def env_step_passive_checker(env, action) -> tuple
def env_render_passive_checker(env) -> Any

Import

from gymnasium.utils.passive_env_checker import (
    check_observation_space,
    check_action_space,
    env_reset_passive_checker,
    env_step_passive_checker,
    env_render_passive_checker,
)

I/O Contract

Inputs

Name Type Required Description
space gymnasium.Space Yes (for check_*_space) The observation or action space to validate
env gymnasium.Env Yes (for env_*_passive_checker) The environment instance to check
action Any Yes (for env_step_passive_checker) The action to pass to env.step()
kwargs dict No Additional keyword arguments forwarded to env.reset()

Outputs

Name Type Description
result tuple The unchanged return value from env.reset(), env.step(), or env.render()

Usage Examples

import gymnasium as gym
from gymnasium.utils.passive_env_checker import (
    check_observation_space,
    check_action_space,
    env_reset_passive_checker,
    env_step_passive_checker,
)

env = gym.make("CartPole-v1")

# Validate spaces
check_observation_space(env.observation_space)
check_action_space(env.action_space)

# Validate reset
obs, info = env_reset_passive_checker(env)

# Validate step
result = env_step_passive_checker(env, env.action_space.sample())

Related Pages

Page Connections

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