Gymnasium Wrappers and Recording
Use this sub-skill when a task needs single-environment Gymnasium wrappers: applying wrapper chains, inspecting wrapped environments, writing custom wrappers, recording episode statistics or videos, and diagnosing wrapper or render-mode failures.
Start Here
- Build the base environment with
gymnasium.make(...); most made environments already includeTimeLimit<OrderEnforcing<PassiveEnvChecker<...>>>unless the spec/options disable parts of that stack. - Add wrappers outside-in:
env = Wrapper(env, ...); the last wrapper assigned is the first object the agent interacts with. - Inspect
envfor the full chain,env.envfor the next inner layer, andenv.unwrappedfor the original base environment. - After any wrapper that changes observations or actions, verify
env.observation_space,env.action_space,reset(), and onestep()agree. - Use
RecordEpisodeStatisticsfor lightweight metrics; addRecordVideoonly when the environment was created with image-returning rendering such asrender_mode="rgb_array"andmoviepyis installed.
Route by Task
| Task | Read |
| --- | --- |
| Choose or order built-in wrappers | references/wrapper-catalog.md |
| Record episode returns, lengths, videos, or render frames | references/recording-and-rendering.md |
| Write Wrapper, ObservationWrapper, ActionWrapper, or RewardWrapper subclasses | references/custom-wrappers.md |
| Diagnose wrapper order, changed spaces, render/video, image wrapper, Atari, or array conversion errors | references/troubleshooting.md |