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 abstractEnvironment 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.- 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 implementenv_response().
has_error- Stops on anyvf.Errorinstate["error"]prompt_too_long- Stops if prompt exceeds model context lengthmax_turns_reached- Stops aftermax_turnsiterationshas_final_env_response- Stops whenstate["final_env_response"]is set
ToolEnv
Adds tool calling capabilities with stateless Python functions. Tools are automatically converted to OpenAI-compatible schemas.- Function name → tool name
- Type hints → parameter types
- Docstring → tool description and parameter descriptions
- Stops when model responds without tool calls (built-in
no_tools_calledcondition) - Configurable error handling via
stop_errorsparameter
StatefulToolEnv
For tools that require per-rollout state (sandbox IDs, database connections, session handles).- Add tools with
args_to_skipfor hidden parameters - Initialize state in
setup_state() - Inject state values in
update_tool_args()
SandboxEnv
Provides containerized bash execution using Prime Intellect’s Sandboxes.bash(command: str)- Execute shell commands in the sandbox
- 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
ExtendsSandboxEnv with a persistent Python REPL.
python(code: str)- Execute Python code in the persistent REPL
MCPEnv
Integrates with MCP (Model Context Protocol) servers.- 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:dataset/eval_dataset- Training and evaluation datasets (can beDatasetBuilderfor lazy loading)system_prompt- Prepended to all prompts as a system messagefew_shot- Example messages inserted after system promptparser- For extracting structured output (e.g.,vf.XMLParser)rubric- Reward functions and scoring logicsampling_args- Default generation parameters (temperature, top_p, etc.)max_seq_len- Maximum sequence length for tokenizationscore_rollouts- Whether to score rollouts (disable for pure generation)
Core Methods
Generation
GenerateOutputs with outputs (list of RolloutOutput) and metadata
Evaluation
Dataset Access
Environment Groups
EnvGroup combines multiple environments for multi-task training:
- Concatenates all sub-environment datasets
- Routes each rollout to the appropriate environment via
taskcolumn - 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:Signaling Early Termination
Setstate["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.