Implementation:Farama Foundation Gymnasium Check Env
| Knowledge Sources | |
|---|---|
| Domains | Reinforcement_Learning, Testing |
| Last Updated | 2026-02-15 03:00 GMT |
Overview
Concrete tool for validating custom RL environment implementations against the Gymnasium API contract.
Description
The check_env function performs comprehensive validation of a Gymnasium environment. It checks observation and action spaces, reset return types, seed determinism, step determinism, render mode compliance, and close safety. It raises AssertionError or TypeError with descriptive messages when violations are found and logs warnings for non-critical issues.
Usage
Call check_env after instantiating a custom environment (without make() wrappers). Use skip_render_check=True in environments without rendering support or in CI environments without display access.
Code Reference
Source Location
- Repository: Gymnasium
- File: gymnasium/utils/env_checker.py
- Lines: L351-452
Signature
def check_env(
env: gym.Env,
warn: bool = None,
skip_render_check: bool = False,
skip_close_check: bool = False,
):
"""Check that an environment follows Gymnasium's API.
Args:
env: The environment instance to validate
warn: Ignored (previously silenced warnings)
skip_render_check: Whether to skip render method checks
skip_close_check: Whether to skip close method checks
Raises:
AssertionError: If environment violates the API contract
TypeError: If environment doesn't inherit from gymnasium.Env
"""
Import
from gymnasium.utils.env_checker import check_env
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| env | gym.Env | Yes | Environment instance to validate (unwrapped preferred) |
| skip_render_check | bool | No | Skip render validation (default False) |
| skip_close_check | bool | No | Skip close validation (default False) |
Outputs
| Name | Type | Description |
|---|---|---|
| (none) | None | Passes silently if valid; raises exceptions on failure |
Usage Examples
Validate Custom Environment
from gymnasium.utils.env_checker import check_env
# Create environment directly (not via make())
env = GridWorldEnv(size=5, render_mode="rgb_array")
# Run full validation
check_env(env)
# Skip render check for headless CI
check_env(env, skip_render_check=True)
Integration Test Pattern
import pytest
from gymnasium.utils.env_checker import check_env
def test_custom_env_api_compliance():
env = MyCustomEnv()
check_env(env, skip_render_check=True)
env.close()