How openai/gym works
Gym provides a standard reinforcement-learning environment API and a catalog of environments. The principal workflow is to request a versioned environment with gym.make, then reset it and repeatedly step it using actions drawn from its action space, receiving observations and rewards. Environments span classic control, Box2D, MuJoCo, and toy-text domains. Core API wrappers transform environment interactions; spaces describe action and observation values, while vector environments support batched interaction and wrappers add rollout features such as video recording. Some subsystem links are documented rather than verified in sampled implementation excerpts.
Main entry points: core.py Environment contract · space.py Action and observation spaces · registration.py Environment registry · record_video.py Video recording wrapper
Components 22
Environment API
- Gym API
gym/__init__.py - Environment registry
gym/envs/registration.py - Environment contract
gym/core.py - Random seeding
gym/utils/seeding.py
Environment Families
- Classic control
gym/envs/classic_control - Box2D tasks
gym/envs/box2d - MuJoCo tasks
gym/envs/mujoco - Toy-text tasks
gym/envs/toy_text
Spaces and Batching
- Action and observation spaces
gym/spaces/space.py - Continuous Box space
gym/spaces/box.py - Structured spaces
gym/spaces/dict.py - Vector environments
gym/vector/vector_env.py - Async vector execution
gym/vector/async_vector_env.py - Shared observations
gym/vector/utils/shared_memory.py
Rollout Utilities
- Environment wrappers
gym/core.py - Step API compatibility
gym/utils/step_api_compatibility.py - Passive environment checks
gym/utils/passive_env_checker.py - Video recording wrapper
gym/wrappers/record_video.py - Video recorder
gym/wrappers/monitoring/video_recorder.py - Logging
gym/logger.py - Message colorization
gym/utils/colorize.py
Other components
- RL user
Connections 22
- RL user → Gym API: requests environment
README.md - Gym API → Environment registry: exposes make
gym/__init__.py - RL user → Environment registry: selects environment
README.md - Environment registry → Classic control: creates CartPole
README.md - Classic control → Environment contract: implements API
gym/envs/classic_control/acrobot.py - Box2D tasks → Environment contract: implements API
- MuJoCo tasks → Environment contract: implements API
- Toy-text tasks → Environment contract: implements API
- RL user → Environment contract: resets and steps
README.md - Environment contract → Action and observation spaces: declares spaces
- Action and observation spaces → Continuous Box space: provides Box
gym/spaces/__init__.py - Action and observation spaces → Structured spaces: provides Dict
gym/spaces/__init__.py - Environment contract → Random seeding: uses seeding
gym/core.py - Environment contract → Environment wrappers: defines wrapper types
gym/core.py - Vector environments → Action and observation spaces: batches spaces
gym/vector/vector_env.py - Async vector execution → Shared observations: allocates observations
gym/vector/async_vector_env.py - Shared observations → Action and observation spaces: handles space types
gym/vector/utils/shared_memory.py - Video recording wrapper → Video recorder: starts recorder
gym/wrappers/record_video.py - Video recording wrapper → Environment contract: wraps environment
gym/wrappers/record_video.py - Logging → Message colorization: colors messages
gym/logger.py - Environment contract → Step API compatibility: imports compatibility helper
gym/core.py - Passive environment checks → Action and observation spaces: checks spaces
gym/utils/passive_env_checker.py