Skip to main content

Overview

Environments are the core abstraction in Verifiers that define how language models interact with tasks. Each environment orchestrates the full lifecycle of a rollout: loading data, managing model interactions, executing tools or game logic, and computing rewards.

Environment Hierarchy

All environments inherit from the abstract Environment base class and implement a rollout() method. The class hierarchy provides progressively more specialized interaction patterns:

Environment Types

SingleTurnEnv

The simplest environment for single-response tasks where the model generates one completion per prompt.
Key characteristics:
  • One model response per rollout
  • No environment feedback loop
  • Perfect for Q&A, classification, or completion tasks

MultiTurnEnv

Enables multi-turn interactions where the environment responds after each model turn. Subclasses must implement env_response().
Built-in stop conditions:
  • has_error - Stops on any vf.Error in state["error"]
  • prompt_too_long - Stops if prompt exceeds model context length
  • max_turns_reached - Stops after max_turns iterations
  • has_final_env_response - Stops when state["final_env_response"] is set
Constructor parameters:

ToolEnv

Adds tool calling capabilities with stateless Python functions. Tools are automatically converted to OpenAI-compatible schemas.
Tool schema extraction:
  • Function name → tool name
  • Type hints → parameter types
  • Docstring → tool description and parameter descriptions
Stop behavior:
  • Stops when model responds without tool calls (built-in no_tools_called condition)
  • Configurable error handling via stop_errors parameter

StatefulToolEnv

For tools that require per-rollout state (sandbox IDs, database connections, session handles).
Pattern:
  1. Add tools with args_to_skip for hidden parameters
  2. Initialize state in setup_state()
  3. Inject state values in update_tool_args()

SandboxEnv

Provides containerized bash execution using Prime Intellect’s Sandboxes.
Built-in tool:
  • bash(command: str) - Execute shell commands in the sandbox
Lifecycle:
  • Sandboxes are created in setup_state() (per rollout)
  • Destroyed in cleanup handlers after each rollout
  • All setup logic should be in start_command, not awaited until first use

PythonEnv

Extends SandboxEnv with a persistent Python REPL.
Built-in tool:
  • python(code: str) - Execute Python code in the persistent REPL

MCPEnv

Integrates with MCP (Model Context Protocol) servers.
Features:
  • Automatically discovers and exposes MCP server tools
  • Manages server lifecycle
  • Supports multiple concurrent MCP servers

Base Environment Class

Constructor Parameters

All environments accept these common parameters:
Key parameters:
  • dataset / eval_dataset - Training and evaluation datasets (can be DatasetBuilder for lazy loading)
  • system_prompt - Prepended to all prompts as a system message
  • few_shot - Example messages inserted after system prompt
  • parser - For extracting structured output (e.g., vf.XMLParser)
  • rubric - Reward functions and scoring logic
  • sampling_args - Default generation parameters (temperature, top_p, etc.)
  • max_seq_len - Maximum sequence length for tokenization
  • score_rollouts - Whether to score rollouts (disable for pure generation)

Core Methods

Generation

Returns: GenerateOutputs with outputs (list of RolloutOutput) and metadata

Evaluation

Dataset Access

Environment Groups

EnvGroup combines multiple environments for multi-task training:
Behavior:
  • Concatenates all sub-environment datasets
  • Routes each rollout to the appropriate environment via task column
  • Aggregates metrics across all environments
Environment groups are particularly useful for curriculum learning and multi-task RL training where you want to train a single model across diverse task types.

Advanced Customization

Custom Stop Conditions

Define custom termination logic with the @vf.stop decorator:

Resource Management

Use lifecycle decorators for setup and cleanup:
Cleanup methods must be idempotent (safe to call multiple times) and handle errors gracefully to ensure cleanup completes even when resources are in unexpected states.

Signaling Early Termination

Set state["final_env_response"] to bypass model response and end the rollout:

Integration Examples

TextArena Integration

Wrapper for text-based game environments:

ReasoningGym Integration

Procedural reasoning tasks:

Browser Automation

Browserbase integration with DOM or vision-based control:
See the Integrations and Experimental Environments section in the main environments guide for more details on third-party integrations.