Implementation:Farama Foundation Gymnasium Gymnasium Make
| Knowledge Sources | |
|---|---|
| Domains | Reinforcement_Learning, Environment_Management |
| Last Updated | 2026-02-15 03:00 GMT |
Overview
Concrete tool for instantiating registered RL environments provided by the Gymnasium library.
Description
The gymnasium.make function is the primary entry point for creating Gymnasium environments. It resolves a string ID or EnvSpec to an environment class, instantiates it with the provided kwargs, and applies a standard wrapper stack: PassiveEnvChecker (API validation), OrderEnforcing (ensures reset before step), TimeLimit (episode truncation), and any additional wrappers specified in the EnvSpec. It also handles render mode negotiation, automatically applying HumanRendering or RenderCollection wrappers when needed.
Usage
Import this function whenever you need to create a Gymnasium environment instance. Use string IDs for registered environments (e.g., "CartPole-v1", "Blackjack-v1") or pass an EnvSpec object directly. Pass max_episode_steps to override the default truncation limit.
Code Reference
Source Location
- Repository: Gymnasium
- File: gymnasium/envs/registration.py
- Lines: L641-829
Signature
def make(
id: str | EnvSpec,
max_episode_steps: int | None = None,
disable_env_checker: bool | None = None,
**kwargs: Any,
) -> Env:
"""Creates an environment previously registered with gymnasium.register or an EnvSpec.
Args:
id: A string for the environment id or an EnvSpec.
max_episode_steps: Maximum length of an episode, overrides the registered
EnvSpec max_episode_steps. Using -1 will not apply the TimeLimit wrapper.
disable_env_checker: If to add PassiveEnvChecker, None defaults to the
EnvSpec disable_env_checker value.
**kwargs: Additional arguments to pass to the environment constructor.
Returns:
An instance of the environment with wrappers applied.
"""
Import
import gymnasium as gym
# Usage:
env = gym.make("CartPole-v1")
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| id | str or EnvSpec | Yes | Environment identifier string (e.g., "Blackjack-v1") or EnvSpec object |
| max_episode_steps | int or None | No | Override maximum steps per episode; -1 disables TimeLimit |
| disable_env_checker | bool or None | No | Whether to disable PassiveEnvChecker wrapper |
| **kwargs | Any | No | Additional constructor arguments passed to the environment |
Outputs
| Name | Type | Description |
|---|---|---|
| env | gymnasium.Env | Fully wrapped environment instance ready for interaction |
Usage Examples
Basic Environment Creation
import gymnasium as gym
# Create a basic environment
env = gym.make("CartPole-v1")
# Create with custom max steps
env = gym.make("CartPole-v1", max_episode_steps=100)
# Create with render mode
env = gym.make("LunarLander-v3", render_mode="human")
# Create with environment-specific kwargs
env = gym.make("FrozenLake-v1", map_name="8x8", is_slippery=False)
Training Loop Usage
import gymnasium as gym
# Create environment with statistics tracking
env = gym.make("Blackjack-v1", sab=True)
env = gym.wrappers.RecordEpisodeStatistics(env, buffer_length=100)
obs, info = env.reset(seed=42)
for _ in range(1000):
action = env.action_space.sample()
obs, reward, terminated, truncated, info = env.step(action)
if terminated or truncated:
obs, info = env.reset()
env.close()