Safety Gym is an open-source toolkit that provides a standardized set of constrained reinforcement learning environments. It places an agent in a continuous control setting where it must achieve a primary objective—such as navigation or velocity tracking—while simultaneously avoiding a configurable array of hazardous elements and unsafe states. The environments are built on the MuJoCo physics engine, enabling realistic robot locomotion and interaction dynamics.
Glossary
Safety Gym

What is Safety Gym?
Safety Gym is a suite of reinforcement learning environments designed by OpenAI to benchmark the ability of agents to optimize for a goal while satisfying complex safety constraints.
The suite introduces a critical evaluation paradigm by measuring not just reward maximization but constraint violation rates. It includes a variety of pre-configured robots (Point, Car, Doggo) and tasks (Goal, Button, Push), allowing researchers to benchmark safe exploration algorithms like Constrained Policy Optimization (CPO) and Lagrangian methods against a common, reproducible standard for AI safety research.
Key Features of Safety Gym
A suite of reinforcement learning environments designed by OpenAI to benchmark the ability of agents to optimize for a goal while satisfying complex safety constraints.
Constrained Markov Decision Processes
Safety Gym formalizes safe exploration as a Constrained Markov Decision Process (CMDP). Unlike standard RL, the agent must maximize cumulative reward while keeping a separate cost function below a specified threshold. This mathematically defines the trade-off between task performance and safety violations. The agent receives both a reward signal for goal completion and a cost signal for entering unsafe states, enabling the study of algorithms that optimize for both simultaneously.
Configurable Safety Benchmarks
The suite provides a matrix of difficulty through three configurable axes:
- Task: Goal, Button, Push, or Reach objectives
- Robot: Point (simple), Car (non-holonomic), or Doggo (quadrupedal locomotion)
- Level: 0 (open space), 1 (static obstacles), or 2 (dynamic obstacles)
This combinatorial design allows researchers to systematically evaluate how algorithmic safety scales with environment complexity and agent morphology.
Hazards and Safety Objects
Environments are populated with procedurally generated safety-critical entities:
- Hazards: Static dangerous zones (pits, fire) that trigger cost on contact
- Vases: Movable objects that incur cost if displaced beyond a velocity threshold
- Pillars: Immovable obstacles that test navigation without safety implications
- Buttons: Goal objects that require precise interaction
- Gremlins: Dynamic adversaries that actively pursue the agent
Each object type tests different aspects of constrained behavior.
Standardized Cost-Reward Metrics
Safety Gym introduces rigorous evaluation protocols beyond simple episodic return:
- Average Episodic Cost: Total safety violations accumulated per episode
- Cost Rate: Violations normalized by episode length
- Constraint Violation Rate: Percentage of episodes exceeding the cost threshold
- Reward-at-Cost: Maximum reward achievable while maintaining cost below a budget
These metrics prevent reward-hacking and provide a standardized comparison across algorithms like CPO, PPO-Lagrangian, and TRPO-Lagrangian.
Gymnasium API Compatibility
Safety Gym extends the standard Gymnasium (formerly OpenAI Gym) interface, making it immediately compatible with existing RL codebases. The environment returns an extended observation dictionary containing:
- Lidar readings: Egocentric distance measurements to surrounding objects
- Velocity and acceleration: Robot proprioceptive state
- Goal and hazard positions: Relative spatial information
This plug-and-play design accelerates adoption and enables direct comparison with unconstrained baselines.
Algorithmic Research Foundation
Safety Gym serves as the canonical benchmark for constrained policy optimization research. It has been used to validate foundational algorithms including:
- Constrained Policy Optimization (CPO) by Achiam et al.
- Reward Constrained Policy Optimization (RCPO)
- Interior-point Policy Optimization (IPO)
- First-Order Constrained Optimization (FOCOPS)
The environment's difficulty scaling reveals failure modes like reward exploitation where agents learn unsafe shortcuts absent proper constraints.
Frequently Asked Questions
Clear, technical answers to the most common questions about OpenAI's Safety Gym—the reinforcement learning benchmark for constrained exploration and safe policy optimization.
Safety Gym is a suite of reinforcement learning environments developed by OpenAI to benchmark an agent's ability to optimize a primary goal while satisfying complex safety constraints. It works by placing an agent—typically a Point, Car, or Doggo robot—in procedurally generated environments filled with hazards and goal objects. The agent receives a reward for completing tasks like reaching a goal or pushing a box, but incurs a cost for entering hazardous regions or colliding with dangerous obstacles. The core mechanism is the constrained Markov decision process (CMDP), where the objective is to maximize cumulative reward subject to a bounded cumulative cost. Safety Gym provides standardized metrics like average episodic return and cost rate, enabling rigorous comparison of constrained RL algorithms such as Constrained Policy Optimization (CPO) and Lagrangian methods against unconstrained baselines like PPO and TRPO.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Explore the core concepts and defensive architectures that intersect with OpenAI's Safety Gym, a foundational benchmark suite for constrained reinforcement learning.
Constrained Markov Decision Processes (CMDPs)
The mathematical framework underlying Safety Gym. A CMDP extends a standard MDP by adding a set of cost functions that the agent must keep below a threshold while maximizing reward. This formalizes the trade-off between task performance and safety constraint satisfaction, allowing researchers to define 'safe' behavior as a budgeted optimization problem rather than a hard-coded rule.
Sim-to-Real Transfer Learning
The process of deploying policies trained in simulation onto physical robots. Safety Gym's physics-based environments serve as a critical testbed for safe sim-to-real transfer, where a policy must not only succeed at a task but also avoid collisions that would damage hardware. Key techniques include dynamics randomization and latent space alignment to bridge the reality gap without violating safety constraints.
Reward Hacking and Specification Gaming
A failure mode where an agent exploits a poorly defined reward function to achieve high scores without completing the intended task. Safety Gym explicitly tests for this by pitting the extrinsic reward against intrinsic safety costs. An agent might learn to hover near the goal without reaching it to avoid triggering a hazard, revealing a reward-cost mismatch that must be corrected through iterative reward shaping.
Lagrangian Methods in RL
The primary algorithmic approach for solving CMDPs. A Lagrangian multiplier dynamically adjusts the penalty weight on safety violations, converting a constrained problem into an unconstrained saddle-point optimization. If the agent violates a constraint, the multiplier increases, forcing the policy to prioritize safety. This adaptive balancing act is central to algorithms like PPO-Lagrangian and TRPO-Lagrangian benchmarked in Safety Gym.
Out-of-Distribution Detection
The ability to identify inputs that differ significantly from the training distribution. In Safety Gym, an agent encounters novel hazard configurations not seen during training. A robust policy must recognize these unfamiliar states and default to a conservative, safety-first behavior rather than extrapolating recklessly. This links to epistemic uncertainty estimation and anomaly detection in neural networks.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us