OGym
OGym is a Rust-native reinforcement learning library inspired by OpenAI Gym. It provides type-safe environments, explicit action and observation spaces, and implementations backed by native Rust, Rapier, and MuJoCo.
Highlights
- Type-safe APIs: Actions and observations are checked through strongly typed spaces instead of untyped adapters.
- Native performance: Environments use compiled Rust implementations with minimal runtime overhead.
- Batch execution: The
BatchEnvironmentabstraction supports high-throughput workloads. - Multiple backends: Classic Control, Toy Text, Rapier2D, and MuJoCo environments share a consistent interface.
- Opt-in native dependencies: The default feature set does not require a MuJoCo installation.
Benchmarks

The chart compares OGym with equivalent Gymnasium environments. Values are mean execution times with standard deviation; lower is better. See the benchmark suite for methodology and reproduction steps.
Supported environments
| Family | Environments | Backend |
|---|---|---|
| Classic Control | Acrobot, CartPole, MountainCar, Pendulum | Native Rust |
| Toy Text | Blackjack, CliffWalking, FrozenLake, Taxi | Native Rust |
| Box2D / Rapier2D | BipedalWalker, LunarLander | Rapier |
| MuJoCo | Ant, HalfCheetah, Hopper, Humanoid, HumanoidStandup, InvertedDoublePendulum, InvertedPendulum, Pusher, Reacher, Swimmer, Walker2d | MuJoCo |
Installation
Add ogym to your Cargo.toml:
[]
= "0.1.0"
MuJoCo support
MuJoCo environments are optional. Enable the mujoco feature and install the
native MuJoCo library separately:
[]
= { = "0.1.0", = ["mujoco"] }
Current limitation: The MuJoCo feature relies on OGym's repository-local patch for
mujoco-rust, which crates.io packages cannot pass on to consumers. Use a source checkout for MuJoCo environments until the patched wrapper is published; the default crates.io feature set is unaffected.
MuJoCo 3.10.0
OGym targets MuJoCo 3.10.0. On Linux x86-64, install the prebuilt archive under the default path expected by the project:
|
Official prebuilt packages are also available for Linux AArch64, macOS universal, and Windows x86-64.
If MuJoCo is installed elsewhere, set MUJOCO_DIR to its root directory and
make its lib directory available to the platform's dynamic linker.
Quick start
The following example runs a CartPole episode with sampled actions:
use ;
Core abstractions
OGym uses three core traits across every backend:
| Trait | Responsibility |
|---|---|
Space |
Defines, samples, and validates action and observation bounds. |
Environment |
Provides reset and step semantics for a single environment. |
BatchEnvironment |
Manages multiple environment instances for high-throughput execution. |
For a detailed design overview, see the architecture documentation.
Development
Common development workflows are available from the repository root:
See the contributor guide for repository structure, testing expectations, and pull request guidance.
Contributing
Bug reports, feature requests, and pull requests are welcome. Discuss major architecture changes in an issue before implementation and include benchmark evidence for performance claims.
License
OGym is distributed under the MIT License.