A unified framework for reinforcement learning environments
Project description
OpenEnv: Agentic Execution Environments
An e2e framework for creating, deploying and using isolated execution environments for agentic RL training, built using Gymnasium style simple APIs.
๐ Featured Example: Train LLMs to play BlackJack using torchforge (PyTorch's agentic RL framework): examples/grpo_blackjack/
๐ฅ GPU Mode Tutorial: End to end tutorial from GPU Mode blog post.
Quick Start
Install the OpenEnv core package:
pip install openenv-core
Install an environment client (e.g., Echo):
pip install git+https://huggingface.co/spaces/openenv/echo_env
Then use the environment:
from echo_env import EchoAction, EchoEnv
# Connect to a running Space
client = EchoEnv(base_url="https://openenv-echo-env.hf.space")
# Reset the environment
result = client.reset()
print(result.observation.echoed_message) # "Echo environment ready!"
# Send messages
result = client.step(EchoAction(message="Hello, World!"))
print(result.observation.echoed_message) # "Hello, World!"
print(result.reward) # 1.3 (based on message length)
# Cleanup
client.close()
For a detailed quick start, check out the docs page.
OpenEnv on partner platforms:
Overview
OpenEnv provides a standard for interacting with agentic execution environments via simple Gymnasium style APIs - step(), reset(), state(). Users of agentic execution environments can interact with the environment during RL training loops using these simple APIs.
In addition to making it easier for researchers and RL framework writers, we also provide tools for environment creators making it easier for them to create richer environments and make them available over familiar protocols like HTTP and packaged using canonical technologies like docker. Environment creators can use the OpenEnv framework to create environments that are isolated, secure, and easy to deploy and use.
The OpenEnv CLI (openenv) provides commands to initialize new environments and deploy them to Hugging Face Spaces.
โ ๏ธ Early Development Warning OpenEnv is currently in an experimental stage. You should expect bugs, incomplete features, and APIs that may change in future versions. The project welcomes bugfixes, but to make sure things are well coordinated you should discuss any significant change before starting the work. It's recommended that you signal your intention to contribute in the issue tracker, either by filing a new issue or by claiming an existing one.
RFCs
Below is a list of active and historical RFCs for OpenEnv. RFCs are proposals for major changes or features. Please review and contribute!
Architecture
Component Overview
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Client Application โ
โ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โ EchoEnv โ โ CodingEnv โ โ
โ โ (EnvClient) โ โ (EnvClient) โ โ
โ โโโโโโโโโโฌโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโโ โ
โโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโ
โ WebSocket โ WebSocket
โ (reset, step, state) โ
โโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโ
โ Docker Containers (Isolated) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ FastAPI Server โ โ FastAPI Server โ โ
โ โ EchoEnvironment โ โ PythonCodeActEnv โ โ
โ โ (Environment base) โ โ (Environment base) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Core Components
1. Web Interface
OpenEnv includes a built-in web interface for interactive environment exploration and debugging. The web interface provides:
- Two-Pane Layout: HumanAgent interaction on the left, state observation on the right
- Real-time Updates: WebSocket-based live updates without page refresh
- Dynamic Forms: Automatically generated action forms based on environment Action types
- Action History: Complete log of all actions taken and their results
The web interface is conditionally enabled based on environment variables:
- Local Development: Disabled by default for lightweight development
- Manual Override: Enable with
ENABLE_WEB_INTERFACE=true
To use the web interface:
from openenv.core.env_server import create_web_interface_app
from your_env.models import YourAction, YourObservation
from your_env.server.your_environment import YourEnvironment
env = YourEnvironment()
app = create_web_interface_app(env, YourAction, YourObservation)
When enabled, open http://localhost:8000/web in your browser to interact with the environment.
2. Environment (Server-Side)
Base class for implementing environment logic:
reset(): Initialize a new episode, returns initialObservationstep(action): Execute anAction, returns resultingObservationstate(): Access episode metadata (Statewith episode_id, step_count, etc.)
3. EnvClient (Client-Side)
Base class for environment communication:
- Handles WebSocket connections to environment server
- Contains a utility to spin up a docker container locally for the corresponding environment
- Type-safe action/observation parsing
4. Container Providers
Manage container deployment:
LocalDockerProvider: Run containers on local Docker daemonKubernetesProvider: Deploy to K8s clusters (future)
5. Models
Type-safe data structures:
Action: Base class for environment actionsObservation: Base class for environment observationsState: Episode state trackingStepResult: Combines observation, reward, done flag
Project Structure
For Environment Creators
Use the CLI to quickly scaffold a new environment:
openenv init my_env
This creates the following structure:
my_env/
โโโ .dockerignore # Docker build exclusions
โโโ __init__.py # Export YourAction, YourObservation, YourEnv
โโโ models.py # Define Action, Observation, State dataclasses
โโโ client.py # Implement YourEnv(EnvClient)
โโโ README.md # Document your environment
โโโ openenv.yaml # Environment manifest
โโโ pyproject.toml # Dependencies and package configuration
โโโ outputs/ # Runtime outputs (logs, evals) - gitignored
โ โโโ logs/
โ โโโ evals/
โโโ server/
โโโ your_environment.py # Implement YourEnvironment(Environment)
โโโ app.py # Create FastAPI app
โโโ requirements.txt # Dependencies for Docker (can be generated)
โโโ Dockerfile # Define container image
Dependency Management
OpenEnv uses pyproject.toml as the primary dependency specification:
- Environment-level
pyproject.toml: Each environment defines its own dependencies - Root-level
pyproject.toml: Contains shared core dependencies (fastapi, pydantic, uvicorn) - Server
requirements.txt: Can be auto-generated frompyproject.tomlfor Docker builds
Development Workflow:
# Install environment in editable mode
cd my_env
pip install -e .
# Or using uv (faster)
uv pip install -e .
# Run server locally without Docker
uv run server --host 0.0.0.0 --port 8000
Benefits:
- โ Client-side extensions: Modify client classes locally without repo changes
- โ Better dependency management: Clear separation between environments
- โ Flexible workflows: Use pip, uv, or Docker for different scenarios
- โ CI/CD ready: Automated dependency generation and validation
See envs/README.md for a complete guide on building environments.
For Environment Users
To use an environment:
- Install the client:
pip install git+https://huggingface.co/spaces/openenv/echo-env - Import:
from echo_env import EchoAction, EchoEnv - Create client:
client = EchoEnv(base_url="https://openenv-echo-env.hf.space") - Interact:
client.reset(),client.step(action),client.state() - Cleanup:
client.close()
See example scripts in examples/ directory.
CLI Commands
The OpenEnv CLI provides commands to manage environments:
openenv init <env_name>- Initialize a new environment from templateopenenv push [--repo-id <repo>] [--private]- Deploy environment to Hugging Face Spaces
Quick Start
# Create a new environment
openenv init my_game_env
# Deploy to Hugging Face (will prompt for login if needed)
cd my_game_env
openenv push
For detailed options: openenv init --help and openenv push --help.
Design Principles
- Separation of Concerns: Clear client-server boundaries
- Type Safety: Strongly-typed actions, observations, and state
- Container Isolation: Each environment runs in its own container
- Simple APIs: Minimal, intuitive interfaces
Development
Installation
# Clone the repository
git clone https://github.com/meta-pytorch/OpenEnv.git
cd OpenEnv
# Install core package in editable mode
pip install -e .
# Or using uv (faster)
uv pip install -e .
Running Tests
OpenEnv uses a modular dependency structure: the core package is minimal, and each environment has its own dependencies. This means some tests require environment-specific packages.
# Install pytest (required for running tests)
uv pip install pytest
# Run all tests (skips tests requiring uninstalled dependencies)
PYTHONPATH=src:envs uv run pytest tests/ -v --tb=short
# Run a specific test file
PYTHONPATH=src:envs uv run pytest tests/envs/test_echo_environment.py -v
To run environment-specific tests, install that environment's dependencies:
# Example: Install coding_env with dev dependencies (includes smolagents + pytest)
uv pip install -e "envs/coding_env[dev]"
# Then run coding_env tests
PYTHONPATH=src:envs uv run pytest tests/envs/test_python_codeact_rewards.py -v
Tests will be automatically skipped if their required dependencies aren't installed.
Requirements
- Python 3.10+
- Docker Desktop or Docker Engine
- FastAPI >= 0.104.0
- Uvicorn >= 0.24.0
- Requests >= 2.25.0
- Environment-specific dependencies (e.g., smolagents for coding_env)
Supported RL Tools
The goal of this project is to support a broad set of open and closed tools to help standardize the agentic RL community. If you have a project that supports OpenEnv environments, please put up a PR to add your tool name along with a link to your documentation.
torchforge
See GRPO BlackJack training example: examples/grpo_blackjack/
TRL
See the TRL example on how to integrate OpenEnv environments with GRPO training.
Unsloth
See the 2048 game example based on gpt-oss: Colab notebook
SkyRL
See the SkyRL example on how to train on OpenEnv environments with SkyRL.
ART
See the ART example on how OpenEnv environments can be used to train models with ART.
Oumi
See the Oumi example on how OpenEnv environments can be used to train models with Oumi.
Example Environments
Echo Environment
A simple environment that echoes back messages with metadata. Perfect for:
- Testing the HTTP server infrastructure
- Learning the framework basics
- Verifying container deployment
Coding Environment
Executes arbitrary Python code in a sandboxed environment. Features:
- Safe code execution using smolagents
- Capture stdout, stderr, and exit codes
- Persistent execution context within episodes
- Error handling with detailed messages
See: envs/coding_env/README.md
Community Support & Acknowledgments
This is an open and community-centric project. If you would like to add your name here, please put up a pull request and tag @jspisak for review. Ty!!
Supporters include: Meta-PyTorch, Hugging Face, Scaler AI Labs, Patronus AI, Surge AI, LastMile AI, Unsloth AI, Reflection AI, vLLM, SkyRL (UC-Berkeley), LightningAI, Axolotl AI, Stanford Scaling Intelligence Lab, Mithril, OpenMined, Fleet AI, Halluminate, Turing, Scale AI ..
And we'd also like to acknowledge the team at Farama Foundation as the OpenEnv API was heavily inspired by the work you all have done on Gymnasium. Cheers!
License
BSD 3-Clause License (see LICENSE file)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openenv_core-0.2.1.tar.gz.
File metadata
- Download URL: openenv_core-0.2.1.tar.gz
- Upload date:
- Size: 102.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0caa44411af7d866e451e50744d1adab57cdf9a2cf7a1b3f81042675110aebc7
|
|
| MD5 |
d833f1890d70461d95b725968c15c837
|
|
| BLAKE2b-256 |
d1d3d2cef0e459158c9410f073ffd2ad6eca7c09232e7c53d4987acc0b942d28
|
File details
Details for the file openenv_core-0.2.1-py3-none-any.whl.
File metadata
- Download URL: openenv_core-0.2.1-py3-none-any.whl
- Upload date:
- Size: 121.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5868722833df3220b7a3288f581e6c0825c2d8fae42d932ff90d2bb60765813a
|
|
| MD5 |
a76c0b87d4d2c890596780a0447c7f8a
|
|
| BLAKE2b-256 |
a15aa7f8b0e53eac45faedcf6fbfacdd28a104f815d3471f2deceefb4234d8be
|