Guide · RL Environment Design
OpenEnv explained: the reset, step and state contract for agentic RL environments
OpenEnv gives every agentic RL environment the same Gymnasium-style interface over a WebSocket. This guide covers what that interface promises, what it leaves to you, and where API-backed environments get the reset wrong.
Last reviewed against the sources listed at the end of this guide.
At a glance
- What it is
- An interface library and framework for RL post-training with isolated execution environments
- Interface
reset(),step()andstate(), sync or async, over a WebSocket- Packaging
- Each environment is a Docker image: run it locally, on a cloud sandbox or as a Hugging Face Space
- Install
pip install openenv- License
- BSD 3-Clause
- Status
- Early development; the README warns that APIs may still change
What OpenEnv is
OpenEnv describes itself as an end-to-end framework for creating, deploying and using isolated execution environments for agentic RL, with a Gymnasium-style API. In practice it is two things: a contract every environment implements (reset(), step() and state()), and the tooling around that contract, a CLI that scaffolds, validates and deploys environments, client classes that talk to them, and integrations with the trainers that consume them.
The code lives at openenv/OpenEnv on GitHub and the documentation on Hugging Face. The project is governed by a technical committee whose listed members include Meta-PyTorch, Hugging Face, Reflection, Unsloth, Modal, Prime Intellect, Nvidia, Mercor, Fleet AI, Microsoft, RadixArk and Nebius, and it credits the Farama Foundation's Gymnasium as the inspiration for its API.
The problem it addresses is the one this site keeps returning to: every training framework and every environment used to agree on the agent-environment boundary privately. OpenEnv makes that boundary a network protocol, so an environment built once can be trained against from TRL, SkyRL, Unsloth or any other framework that speaks it, and run anywhere a container runs.
The contract: reset(), step() and state()
OpenEnv follows a client-server model. Your agent (the client) sends structured actions; the environment (the server) returns observations, rewards and episode status. Five types carry the whole exchange:
| Type | What it holds |
|---|---|
| Action | A structured command. Each environment defines its own schema by subclassing Action. |
| Observation | What the agent can see after a step. Every observation carries done and reward fields. |
| State | Server-side episode bookkeeping, at least episode_id and step_count, read by the client with state(). |
| StepResult | What the client gets back from a step: observation, reward, done and metadata. |
| Rubric | A composable unit of reward computation passed to the environment. |
The loop looks like Gymnasium's, with one difference that trips people porting code: step() returns an observation (wrapped in a StepResult on the client), not a tuple.
with env.sync() as client:
result = client.reset()
while not result.done:
obs = result.observation
action = decide_action(obs)
result = client.step(action)
learn(result.reward)| Gymnasium | OpenEnv | |
|---|---|---|
| Where the environment runs | In your training process | In its own server, usually a container, reached over HTTP or a WebSocket |
What step() returns | A tuple: observation, reward, terminated, truncated, info | An observation carrying done and reward (a StepResult on the client) |
| Episode bookkeeping | Kept by your code or wrappers | A State on the server with episode_id and step_count |
| Where reward is computed | Inside step(), often reshaped by wrappers | Inside the environment, composed from rubrics |
| Sharing an environment | Copy the code and its dependencies | Push the image to a registry or a Hugging Face Space |
Sessions, seeds and what a reset actually resets
You pass the server the environment class, not an instance, and it creates one instance per client session. The full signatures are reset(self, seed=None, episode_id=None, **kwargs) and step(self, action, timeout_s=None, **kwargs), so a trainer can pin both the seed and the episode id it records in its trajectories.
Two settings decide how far that isolation goes. SUPPORTS_CONCURRENT_SESSIONS on the environment should be True only if instances share no mutable state, and max_concurrent_envs on the server caps how many sessions run at once (the scaffold sets it to 1).
That is the line to read carefully. OpenEnv gives each session its own environment instance, and the scaffolded reset() starts a new State. It does not know what your environment talks to. If the environment wraps a database, a sandbox account or a third-party API, the world behind it is shared across sessions and survives every reset unless your reset() puts it back. That is the episodic reset contract, and the reason worker isolation has to be decided before you raise max_concurrent_envs.
- Make
reset()restore every piece of state the agent can change, not just the episode counter. - Use the
seedargument to pick the starting world, so the same seed gives the same first observation. - Record
episode_idandstep_countfromstate()with each trajectory; they are what makes a run reproducible after the fact. - Leave
SUPPORTS_CONCURRENT_SESSIONSoff until two sessions provably cannot see each other's writes.
Rewards live inside the environment
In OpenEnv, rewards are computed inside the environment, not by the training code. A rubric is passed to the environment's constructor; reset() calls self._reset_rubric() and step() calls self._apply_rubric(action, observation). Rubrics combine with WeightedSum, Gate and Sequential, can use LLM judges for subjective criteria, and handle delayed rewards with TrajectoryRubric.
Keeping reward next to state is the right default: the rubric sees the world the action changed, not a summary the client reconstructed. It also means a reward can only be as honest as the environment's state. If the backend fakes a write, the rubric rewards the fake, which is how reward hacking through fidelity gaps starts. For how to split a reward across API calls, see reward shaping for agents calling external APIs.
Simulation mode, production mode and MCP tools
An OpenEnv server runs in one of two modes. Simulation mode, the default, is for training and evaluation: the caller owns the episode through /reset, /step and /state. Production mode serves the environment's MCP tools to an agent over /mcp, with no episode control. Set it with mode= on create_app or the OPENENV_MODE variable.
For MCP environments this creates a trap. In simulation mode a tool call is an action: send it as step(CallToolAction(...)) and it counts as a step, gets a reward and lands in the trajectory. The client's call_tool() goes to /mcp instead and never produces a reward, a step count or done. A training loop that calls tools through call_tool() will look like it is working while learning nothing from those calls.
Building your own environment
The CLI covers the whole path. You need Python 3.10 or newer, uv, and Docker only to build or run the image locally.
pip install openenv
openenv init my_env # scaffold an environment
openenv validate my_env --level static --skip-build # check it against the OpenEnv contract
openenv push my_env # deploy it to Hugging Face SpacesThe scaffold is a Python package: models.py for the action and observation, client.py, an openenv.yaml manifest that declares the reward range, resources and capabilities the environment promises, and a server/ folder with the environment, a FastAPI app built with create_app, and a Dockerfile. If you already have a Prime Intellect Verifiers or ORS/OpenReward environment, openenv import wraps it instead of starting from scratch.
Design the action and observation types with the same care as any other environment: a typed action schema is where tool-call constraints belong, and the observation is where you decide how much of an API response the agent reads.
Training against an OpenEnv environment
Any framework that can call an environment can train on it. OpenEnv's docs describe two patterns: environments as tools, where the trainer runs the multi-turn loop and the environment supplies tools and reward (TRL's GRPOTrainer takes an environment_factory for this), and real agent harnesses, where an agent such as a coding harness runs its own loop and OpenEnv's Harbor integration captures every model call for training.
The README lists integrations with ART, Lightning AI, Miles, Oumi, SkyRL, torchforge, TorchTitan-RL, TRL and Unsloth. The list grows by pull request, so check the README for the current set and each framework's own docs for the version that supports it.
Wrapping a third-party API as an OpenEnv environment
Many agentic tasks are API tasks: open a GitHub issue, refund a Stripe charge, post to a Slack channel. OpenEnv standardises how the trainer reaches the environment; what sits behind the environment's tools is still your choice, and it decides whether reset() can keep its promise.
| Backend behind the tools | Can reset() restore it? | What goes wrong |
|---|---|---|
| The live API or a vendor sandbox | Rarely: state is shared and outlives the episode | Rate limits, credentials in the container, episodes that see each other's writes |
| A stateless mock | Trivially, because it never changes | Reads ignore writes, so the agent learns the wrong causal model |
| A stateful simulator per session | Yes: restore or reseed it in reset() | Only as good as its fidelity to the real API; check how the vendor verifies it |
The third row is the one that fits OpenEnv's model: a simulator inside the environment's container, one per session, reseeded on each reset. Rystic, for example, builds stateful simulators of APIs such as Slack, GitHub and Stripe that run locally or in CI; evaluate an option like that alongside writing your own. Scaffolding a simulated API backend as a Gym environment walks through the shape of that environment, and versioning the simulator matters as soon as more than one team trains against it.
- Run the backend inside the environment's image, so each session gets its own copy.
- In
reset(seed=...), restore the backend to a seeded starting world before returning the first observation. - Route every tool call through
step()so it is rewarded, counted and recorded. - Compute the reward from the backend's state, not from the tool's response text.
- Keep secrets out of the image; a simulator should need no live credentials.
Frequently asked questions
Is OpenEnv a replacement for Gymnasium?
It borrows Gymnasium's reset and step loop and credits it as the inspiration, but it solves a different problem: running environments as isolated servers that LLM training frameworks reach over the network. Classic control and simulation work that runs in-process is still Gymnasium's territory.
Who maintains OpenEnv?
A technical committee that coordinates direction, RFCs and releases in public. The README lists its current members, including Meta-PyTorch and Hugging Face; check the README for the current list.
Is OpenEnv stable enough to build on?
The README says it is in early development and that APIs may still change. Pin the openenv version you build against and read the release notes on GitHub before upgrading.
Does OpenEnv cost anything?
The library is open source under the BSD 3-Clause license. Where you run environments can cost money: check Hugging Face's pricing for Spaces hardware, or your cloud provider's for containers and sandboxes.
Can I use an existing Verifiers environment with OpenEnv?
Yes: openenv import detects Prime Intellect Verifiers and ORS/OpenReward sources and generates an OpenEnv wrapper around them.
Where do I find ready-made environments?
The README points to more than 40 in the environment catalog in OpenEnv's documentation and on the OpenEnv organization on Hugging Face, from games and coding sandboxes to browsers and finance.





