---
title: "Hugging Face OpenEnv integration"
description: "Run OpenEnv Terminus episodes in E2B sandboxes. Policies inspect, run and repair code over several turns, and you get a first reward without a GPU."
url: "https://e2b.dev/integrations/openenv"
---

# Hugging Face OpenEnv

> OpenEnv's Terminus environment runs terminal commands in E2B, so a policy can inspect, run and fix code over several turns. Get a first reward without a GPU.

Training & evals · [All integrations](https://e2b.dev/integrations.md)

## About this integration

- **Maintained by:** E2B
- **How it works:** Terminus environment runs on E2B
- **Environment:** Terminus (OpenEnv 0.8.0)
- **Language:** Python
- **Upstream:** [openenv/OpenEnv · ★ 2.9k](https://github.com/openenv/OpenEnv)
- **Example:** [e2b-cookbook/openenv-terminus-python](https://github.com/e2b-dev/e2b-cookbook/tree/main/examples/openenv-terminus-python)

## Get started

Paste the prompt into your coding agent, or follow the steps yourself.

### Paste this into your coding agent

```text
Add E2B sandboxes to this OpenEnv project.

1. Get the openenv-terminus-python example from the E2B cookbook and install its pinned dependencies with uv sync --frozen.
2. The example needs the E2B_API_KEY environment variable in its .env file. If it isn't set, ask me for my API key from https://console.e2b.dev/?tab=keys. Never hardcode it.
3. Follow the OpenEnv guide at https://docs.e2b.dev/agents/openenv: start the local Terminus server, then run episodes through ReportEpisode so each one resets into a fresh E2B sandbox and is graded on the host.
4. Run the demo once and show me the rewards and the report output that came from the sandbox.
```

## Or set it up yourself

### 1. Get the Terminus example

```bash
git clone https://github.com/e2b-dev/e2b-cookbook.git
cd e2b-cookbook/examples/openenv-terminus-python
uv sync --frozen
cp .env.example .env
```

### 2. Set E2B_API_KEY in .env and start the server

```bash
uv run --frozen uvicorn server:app --host 127.0.0.1 --port 8010
```

### 3. Run the repair demo

```bash
uv run --frozen main.py
```

### 4. Drive an episode from Python

```python
import shlex

from dotenv import load_dotenv
from episode import BUGGY, PROGRAM, ReportEpisode

load_dotenv()
episode = ReportEpisode()
try:
    print(episode.reset())
    print(episode.terminal(f"cat {PROGRAM}; python3 -B {PROGRAM}"))
    fixed = BUGGY.replace(
        '= int(row["amount"])',
        '= totals.get(row["region"], 0) + int(row["amount"])',
    )
    episode.terminal(f"printf %s {shlex.quote(fixed)} > {PROGRAM}")
    print(episode.submit())
    print(episode.get_reward())
finally:
    episode._close()
```

## What runs in the sandbox

Episode code runs in E2B, away from your trainer. The OpenEnv server, inference and training stay on your own compute.

- **Code:** Terminal commands from the policy run in an E2B episode sandbox, through OpenEnv's native reset and step calls.
- **State:** Files persist across steps within an episode. Each command gets a fresh shell, and reset replaces the whole sandbox.
- **Grading:** Submitted code runs in a fresh verifier sandbox with outbound access off. Expected answers stay on the host.
- **Secrets:** Your E2B key stays on the host, and the local server binds to loopback.

## More training & eval tools

Other RL and eval tools that run their rollouts on E2B.

- [Harbor / Terminal-Bench](https://e2b.dev/integrations/harbor.md): Run Harbor and Terminal-Bench trials on E2B and scale evals and rollouts to many parallel sandboxes.
- [Hugging Face TRL](https://e2b.dev/integrations/trl.md): Compute code rewards for TRL GRPO training in E2B sandboxes.
- [DSPy RLMs](https://e2b.dev/integrations/dspy.md): Run DSPy recursive language model (RLM) code in E2B sandboxes.

## Links

- [Get API key](https://console.e2b.dev/?tab=keys)
- [Read the docs](https://docs.e2b.dev/agents/openenv)
- [E2B documentation](https://docs.e2b.dev)
