Safety Gymnasium 2
Safety Gymnasium 2 is the independent LIRA research fork of Safety Gymnasium for safe reinforcement learning. It provides MuJoCo environments with an explicit safety cost.
Documentation · Environment reference · Issue tracker
Why Safety-Gymnasium2?
The original Safety Gymnasium core uses exact pins for Gymnasium, Gymnasium-Robotics, and MuJoCo. The fork updates that stack, adds ranged dependencies with a uv lockfile for development, and tests the supported Python and simulator versions in CI.
| Project | Python | Gymnasium | Gymnasium-Robotics | MuJoCo |
|---|---|---|---|---|
| Original Safety Gymnasium | 3.8+ in package metadata | 0.28.1 | 1.2.2 | 2.3.3 |
| Safety Gymnasium 2 | 3.11+ | 1.2+ | 1.4.2+ | 4.0.1+ |
The fork retains the native six-value step API. Its namespaced single-agent aliases work with standard Gymnasium wrappers, and its vector API preserves terminal observations and costs when lanes reset on the same step.
Environments
| Family | Released tasks | Example |
|---|---|---|
| Navigation | Goal, Button, Push, Circle, Run, FadingEasy, and FadingHard with state observations | SafetyPointGoal0-v0 |
| Velocity | HalfCheetah, Hopper, Swimmer, Walker2d, Ant, and Humanoid | SafetyHalfCheetahVelocity-v2 |
| Multi-Agent Navigation | MultiGoal with Point or Ant | SafetyAntMultiGoal0-v0 |
| Multi-Agent Velocity | Eight MaMuJoCo configurations available through make_ma |
make_ma('Ant', '2x4') |
Single-agent navigation supports Point, Car, Racecar, Doggo, and Ant. Configuration templates such as SafetyPointGoalBase-v0 require explicit task configuration. Keyboard debugging is available with supported Point, Car, and Racecar Debug variants such as SafetyCarGoal2Debug-v0.
Benchmark versions
Safety{Robot}Velocity-v0 and -v1 use Gymnasium's v4 locomotion implementations. -v2 uses upstream v5 observations, rewards, and termination with Safety Velocity v1 costs and horizons. Ant observations change from 27 to 105 values by default, and Humanoid observations change from 376 to 348. The Robotics upgrade also changes some multi-agent observation shapes. For example, Ant with 2x4 changes from 21 to 63 values per agent. See the benchmark notes for what to record with each experiment.
Installation
Use Python 3.11 or newer. From a checkout, install the core package in an active virtual environment.
python -m pip install .
For development, use uv sync --locked. On headless Ubuntu, install libosmesa6 and set MUJOCO_GL=osmesa and PYOPENGL_PLATFORM=osmesa before starting Python.
Quickstart
import safety_gymnasium2 as sg2
with sg2.make('SafetyPointGoal0-v0') as env:
observation, info = env.reset(seed=17)
action = env.action_space.sample()
observation, reward, cost, terminated, truncated, info = env.step(action)
The native step() returns six values, including the safety cost. For a five-value Gymnasium API, import the package to register its aliases and read the cost from info['cost'].
import gymnasium
import safety_gymnasium2 as sg2
with gymnasium.make('SafetyGymnasium2/SafetyPointGoal0Gymnasium-v0') as env:
observation, info = env.reset(seed=17)
observation, reward, terminated, truncated, info = env.step(env.action_space.sample())
cost = info['cost']
See Basic Usage for vectorization, rendering, and customization.
Citing Safety-Gymnasium2
Cite this repository when using the fork in research and record the Git commit used in your experiments.
@misc{safetygymnasium2,
author = {{Safety Gymnasium 2 Contributors}},
title = {Safety Gymnasium 2},
howpublished = {GitHub repository},
url = {https://github.com/LIRA-illinois/safety-gymnasium2}
}
See CITATION.cff for citation metadata. This fork builds on the original Safety Gymnasium project and its benchmark paper.
License
The project uses Apache-2.0. Bundled components have their own notices, including the MIT license. See NOTICE for provenance.
Metadata
Release files for safety-gymnasium2 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| safety_gymnasium2-2.0.0.tar.gz | 336.1 kB | With provenance | Details for safety_gymnasium2-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| safety_gymnasium2-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for safety_gymnasium2-2.0.0-py3-none-any.whl |
Total release size: 790.4 kB
Release files / safety_gymnasium2-2.0.0.tar.gz
| Download URL | safety_gymnasium2-2.0.0.tar.gz |
|---|---|
| Size | 336.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c81559c3281af2bb3b69f36a098520456834b89156c5410dac1a595a989a5b32
|
|
BLAKE2b-256 checksum How to use checksums |
e75fa528f84ce72f2fe8920fe36ceb88b8afa8977057ddbb50edc2c346ce6903
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / safety_gymnasium2-2.0.0-py3-none-any.whl
| Download URL | safety_gymnasium2-2.0.0-py3-none-any.whl |
|---|---|
| Size | 454.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da991c35801a29e80a0606f00b384634881ced46c5be14696f58c96306b37d2c
|
|
BLAKE2b-256 checksum How to use checksums |
579b3a08bfc467bb68d7aedd3e94dd7ba9b3462fd2a2d06724ecc9824342d7f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logSecurity for safety-gymnasium2 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for safety_gymnasium2-2.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.