import asyncio
from echo_env import CallToolAction, 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(
CallToolAction(
tool_name="echo_message",
arguments={"message": "Hello, World!"},
)
)
print(result.observation.result) # "Hello, World!"
print(result.reward)
asyncio.run(main())
is also supported via the wrapper:
Synchronous usage
.sync()
from echo_env import CallToolAction, 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(
CallToolAction(
tool_name="echo_message",
arguments={"message": "Hello, World!"},
)
)
print(result.observation.result)
For a detailed quick start, check out the docs page.
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!
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: 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 CallToolAction, EchoEnv
Use async (recommended) or sync API:
Async (recommended):
async with EchoEnv(base_url="...") as client:
result = await client.reset()
result = await client.step(action)
Sync (via .sync() wrapper):
with EchoEnv(base_url="...").sync() as client:
result = client.reset()
result = client.step(action)
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 template
openenv 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.
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!