SkillAgentSearch skills...

OpenEnv

An interface library for RL post training with environments.

Install / Use

/learn @meta-pytorch/OpenEnv
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<img width="35" height="35" alt="image" src="https://github.com/user-attachments/assets/2700a971-e5d6-4036-b03f-2f89c9791609" /> 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.

PyPI Discord Open In Colab Docs


🚀 Featured Example: Train LLMs to play BlackJack using torchforge (PyTorch's agentic RL framework): examples/grpo_blackjack/

🔥 Zero to Hero Tutorial: End to end tutorial from our GPU Mode lecture and other hackathons.

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:

import asyncio
from echo_env import EchoAction, EchoEnv

async def main():
    # Connect to a running Space (async context manager)
    async with EchoEnv(base_url="https://openenv-echo-env.hf.space") as client:
        # Reset the environment
        result = await client.reset()
        print(result.observation.echoed_message)  # "Echo environment ready!"

        # Send messages
        result = await client.step(EchoAction(message="Hello, World!"))
        print(result.observation.echoed_message)  # "Hello, World!"
        print(result.reward)  # 1.3 (based on message length)

asyncio.run(main())

Synchronous usage is also supported via the .sync() wrapper:

from echo_env import EchoAction, EchoEnv

# Use .sync() for synchronous context manager
with EchoEnv(base_url="https://openenv-echo-env.hf.space").sync() as client:
    result = client.reset()
    result = client.step(EchoAction(message="Hello, World!"))
    print(result.observation.echoed_message)

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 initial Observation
  • step(action): Execute an Action, returns resulting Observation
  • state(): Access episode metadata (State with episode_id, step_count, etc.)

3. EnvClient (Client-Side)

Base class for environment communication:

  • Async by default: Use async with and await for all operations
  • Sync wrapper: Call .sync() to get a SyncEnvClient for synchronous usage
  • 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 daemon
  • KubernetesProvider: Deploy to K8s clusters (future)

5. Models

Type-safe data structures:

  • Action: Base class for environment actions
  • Observation: Base class for environment observations
  • State: Episode state tracking
  • StepResult: 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 from pyproject.toml for 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: Mo
View on GitHub
GitHub Stars1.6k
CategoryDevelopment
Updated9m ago
Forks314

Languages

Python

Security Score

95/100

Audited on Apr 7, 2026

No findings