Skip to main content

OpenEnvEnv

Drop-in OpenEnv integration for running OpenEnv environments in Verifiers.

Overview

OpenEnvEnv provides seamless integration with OpenEnv environments. It automatically manages sandbox deployment, supports both gym (step/reset) and MCP tool contracts, and uses seeds as the dataset mechanism. Key features:
  • Automatic sandbox deployment using Prime Sandboxes
  • Support for both gym and MCP contracts
  • Seed-based dataset generation
  • Custom prompt rendering for observations
  • Pre-built container image support
  • Automatic retry and error handling

Installation

Install with OpenEnv support:
See the OpenEnv integration guide for complete setup details.

Inheritance

Constructor

Parameters

str | Path | None
default:"None"
Path to OpenEnv project directory. If None, infers from calling module’s location (looks for proj/ directory adjacent to caller).
int
default:"100"
Number of training examples to generate.
int
default:"50"
Number of evaluation examples to generate.
int
default:"0"
Starting seed for dataset generation. Each example gets seed + index.
Callable[..., Messages] | None
default:"None"
Required. Function that converts OpenEnv observations to chat messages. Signature: (observation, context, action_schema, contract, seed) -> Messages.
int
default:"-1"
Maximum turns per rollout. -1 for unlimited.
vf.Rubric | None
default:"None"
Rubric for scoring. If None, uses OpenEnvEpisodicSumRubric() which sums step rewards.
int
default:"30"
Timeout waiting for sandbox server to start.
float
default:"1.0"
Poll interval for health checks during startup.
float
default:"2.0"
Timeout for individual health check requests.
float
default:"5.0"
Timeout for schema fetch requests.
int
default:"20"
Maximum attempts waiting for sandbox creation.
int
default:"5"
Maximum retry attempts for transient failures.
float
default:"0.5"
Base delay in seconds for exponential backoff.
float
default:"2.0"
Exponential backoff multiplier.
float
default:"30.0"
Maximum backoff delay in seconds.
float
default:"1e-3"
Jitter added to backoff delays.
Any
Additional arguments passed to MultiTurnEnv.

Build Configuration

OpenEnvEnv requires a .build.json file in the project directory with the following fields:
Generate this file by running:

Key Methods

setup_state

Initialize OpenEnv server and reset environment for this rollout. Flow:
  1. Create sandbox and deploy OpenEnv server
  2. Fetch action schema from /schema endpoint
  3. Connect client (gym or MCP)
  4. Reset environment with seed from state["info"]["seed"]
  5. For MCP: list tools and convert to Verifiers tool format
  6. Store server, client, and schema in state
  7. Render initial prompt via prompt_renderer

env_response

Process model response and step environment. Delegates to:
  • _gym_env_response() for gym contract
  • _mcp_env_response() for MCP contract
Gym flow:
  1. Parse action from latest assistant message
  2. Call client.step(action)
  3. Store reward in trajectory
  4. Render observation via prompt_renderer
MCP flow:
  1. Extract tool calls from latest assistant message
  2. For each tool call, invoke via _mcp_step_tool()
  3. Accumulate rewards and done status
  4. Return tool response messages

openenv_done

Stop condition for gym contract. Returns True when state["openenv_done"] is True.

mcp_no_tool_calls

Stop condition for MCP contract. Returns True when:
  • Environment is done (state["openenv_done"]), OR
  • Last message was assistant message with no tool calls

cleanup_openenv

Clean up OpenEnv resources after rollout:
  • Close client connections
  • Unexpose sandbox port
  • Delete sandbox

teardown_server

Clean up all active servers on environment teardown.

Prompt Renderer

The prompt_renderer is required and must convert OpenEnv observations to messages. Signature:
Requirements:
  • Must return a non-empty list of messages
  • Each message must have role and content fields
  • Content cannot be None

Rubrics

OpenEnvEpisodicSumRubric

Default rubric that sums step rewards from the trajectory:

Example Usage

Gym Contract Environment

MCP Contract Environment

Custom Rubric

Auto-infer Project Path

Contracts

Gym Contract

Traditional reinforcement learning interface:
  • Actions parsed from assistant messages (JSON or single-field text)
  • Environment steps with client.step(action)
  • Returns observation, reward, done
  • Observations rendered to user messages

MCP Contract

Tool-based interface:
  • Actions are tool calls
  • Environment exposes tools via MCP protocol
  • Model calls tools, environment returns tool responses
  • Supports structured tool schemas

Action Parsing (Gym)

For gym contract, actions are parsed from the model’s response:
  1. JSON object: Parsed directly
  2. Single string field: If schema has one required string field, uses raw text
  3. Code fence: Strips json... wrappers

Error Handling

  • Sandbox errors: Raised as vf.SandboxError with logs
  • Startup failures: Includes container logs and local health probe results
  • Contract mismatch: Validates schema matches declared contract
  • Missing renderer: Raises ValueError if prompt_renderer is None
  • Invalid prompts: Validates rendered messages are non-empty with non-null content

Sandbox Management

OpenEnvEnv automatically manages Prime Sandboxes:
  • Creates sandbox from image specified in .build.json
  • Exposes port and waits for health check
  • Retries transient failures with exponential backoff
  • Cleans up sandbox after rollout
  • Provides detailed error messages with logs on failure

See Also