Safety Gymnasium: A Unified Safe Reinforcement Learning Benchmark

Jiaming Ji, Borong Zhang, Jiayi Zhou, Xuehai Pan, Weidong Huang, Ruiyang Sun, Yiran Geng, Yifan Zhong, Josef Dai, Yaodong Yang

TL;DR

Safety-Gymnasium is a comprehensive new benchmark for Safe Reinforcement Learning (SafeRL) that provides a diverse suite of 54 environments—ranging from single-agent navigation to multi-agent dexterous manipulation—alongside SafePO, a library of 16 state-of-the-art algorithms. It modernizes the field by replacing the aging OpenAI Safety Gym with a faster, more customizable, and vision-ready framework built on the latest MuJoCo and Gymnasium standards.

What Problem Does This Paper Address?

Reinforcement Learning (RL) has seen massive success in games, but deploying it in the real world (like autonomous driving or surgery) is risky because standard RL only cares about maximizing rewards, often at the expense of safety. Safe Reinforcement Learning (SafeRL) attempts to solve this by optimizing policies under strict constraints—essentially telling the agent, "Get to the goal, but never hit a wall or exceed a certain speed."

The research community previously relied on OpenAI’s Safety Gym, but that toolkit has become a "legacy" burden: it relies on outdated software (mujoco-py), is notoriously difficult to install, lacks multi-agent support, and has poor performance for vision-based tasks. This paper introduces Safety-Gymnasium to provide a unified, high-performance, and extensible foundation for the next generation of SafeRL research.

Methods

The authors built Safety-Gymnasium from the ground up using the modern Gymnasium API and official MuJoCo Python bindings.

Safety-Gymnasium API Example

Key technical improvements include:

  • Physics Refactoring: By ditching mujoco-py for direct MuJoCo support, they achieved rendering speeds on the CPU that are twice as fast as the original.
  • SafePO Library: They released a "single-file style" algorithm library. This design choice makes it incredibly easy for researchers to tweak a single script to test new ideas without navigating a complex codebase. It includes 16 algorithms covering Lagrangian-based, Projection-based, and PID-controlled methods.
  • Multi-Agent Support: The benchmark extends SafeRL into the multi-agent domain (SafeMARL), where multiple robots must coordinate to complete a task while each adheres to its own safety constraints.
  • GPU Acceleration: For high-dimensional tasks like dexterous hand manipulation, they integrated support for Isaac Gym, allowing for massive parallelization on the GPU.

Environments and Tasks

The paper introduces a massive benchmark suite rather than a static dataset.

Diverse Agents in Safety-Gymnasium

It includes:

  • Gymnasium-based Tasks: 40 navigation tasks (Goal, Button, Push, Circle) and 6 velocity-constrained tasks using a wide variety of robots like Point, Car, Racecar, Ant, and Doggo.
  • Vision-only Tasks: Realistic 3D environments (Race, FormulaOne) that support RGB and RGB-D inputs.
  • Safety-DexterousHands: A collection of high-dimensional tasks involving two Shadow Hands catching and passing objects, built on Isaac Gym.
  • Multi-Agent Environments: Scenarios where agents (like a partitioned Ant robot) must cooperate safely.

Key Insights and Ideas

  • The Lagrangian Trade-off: The authors found that while Lagrangian methods (which turn constraints into "penalties" added to the reward) are powerful, they are highly sensitive to hyperparameters. If the "penalty" is too low, the agent is reckless; if it's too high, the agent becomes too "scared" to move.
  • PID to the Rescue: One of the most effective ways to stabilize SafeRL is incorporating a PID controller into the Lagrangian framework (CPPO-PID). This significantly reduces the "oscillations" where an agent repeatedly switches between being safe/slow and unsafe/fast.
  • Projection vs. Lagrangian: Projection-based methods (like PCPO) tend to be more stable and "centered" in their safety performance compared to the more volatile Lagrangian approaches, though they can sometimes be overly cautious.
  • Fixing "Lidar" Bugs: The authors identified and fixed a significant bug in the original Safety Gym's "Natural Lidar" sensor, which previously failed to detect low-lying objects—a critical flaw for a safety benchmark.

Key Results

  • Performance: Safety-Gymnasium is significantly more efficient, offering a 2x speedup in CPU rendering and supporting large-scale parallel sampling via GPU.
  • Algorithmic Validation: The SafePO library was benchmarked against 54 environments. In velocity tasks, PPO-Lag achieved a 98% reduction in safety violations compared to standard PPO, with only a 45% drop in total reward.
  • Benchmarking Standard: The authors provide a "Normalized Reward" and "Normalized Cost" metric, allowing researchers to easily compare how well different algorithms balance the "speed vs. safety" trade-off across wildly different tasks.

Limitations and Future Work

  • Constraint Diversity: Currently, the benchmark focuses on physical constraints (velocity, collisions). It does not yet encompass "human-centric" safety constraints, which are vital for human-AI collaboration.
  • Sim-to-Real Gap: While the simulation is high-fidelity, the authors acknowledge that transferring these "safe" policies to physical hardware remains a major challenge.
  • Future Directions: The team plans to expand the benchmark to include more complex real-world scenarios and eventually facilitate the transfer of refined policies to physical robotic platforms.

Summary updated

BibTeX
@inproceedings{ji2023safety,
  author = {Jiaming Ji and Borong Zhang and Jiayi Zhou and Xuehai Pan and Weidong Huang and Ruiyang Sun and Yiran Geng and Yifan Zhong and Josef Dai and Yaodong Yang},
  title = {{Safety Gymnasium: A Unified Safe Reinforcement Learning Benchmark}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=TwSzpH7tT6},
}
Figure