reset() and step(), and training libraries such as Hugging Face TRL, Unsloth and SkyRL drive it over HTTP, WebSocket or MCP. MirageOpenEnv is an OpenEnv environment backed by a Mirage workspace. Each episode gets its own copy of the workspace, so a reset takes a snapshot, not a container, and the agent’s shell and file calls run under the workspace’s mounts and the session’s profile.
Install
mcp<2 and Mirage needs mcp>=2.3. OpenEnv’s main branch already supports mcp 2. Once an OpenEnv release supports mcp>=2.3, install it from PyPI instead:
Usage
reset_async() starts from a new copy of base, so answer.txt is gone and base never changes.
Episodes
MirageOpenEnv(ws)copieswsfor every episode withws.copy(). RAM and disk mounts are rebuilt from the workspace’s state, so an episode’s writes never reachws. Remote mounts such as S3 are shared withws, so an episode’s writes to them do.- A copy keeps
ws’s profiles, so a profile’sdenyrules refuse in every episode. It does not keepws’spolicies=[...]instances, which hold state. To refuse with a policy instance, build each episode’s workspace withfactory=, with fresh instances. MirageOpenEnv(factory=build)builds every episode’s workspace withawait build(spec)instead.specis anEpisodeSpecwith the reset’sepisode_id,seedand every other reset parameter inoptions, such as a task’s split and index.setup=runsawait setup(session, spec)after the episode’s workspace is built, to write the task’s files.profile=runs the agent as a session created under that profile, named by the episode id. Without it, the agent acts as the workspace’s default session.- An action sent before the first reset starts an episode, as
reset()would.
Actions and observations
MirageAction(tool=..., arguments=...) names one of Mirage’s seven tools, shell, read, write, edit, ls, grep or glob, with that tool’s MCP input. The arguments are checked against the tool’s schema when the action is built, so an OpenEnv server answers a malformed action with a validation error.
MirageObservation reports:
env.state is a MirageState with the episode’s episode_id, step_count, seed, workspace_id, session_id and cwd.
Rewards
reward=scores each step withawait reward(session, action, observation). The session reads the files the step changed.rubric=takes an OpenEnvRubricand scores with it whenreward=is not set. A reset resets the rubric.done=ends the episode whenawait done(session, action, observation)is true, andmax_steps=ends it after that many steps.timeout_s=sets the default time limit of one action, andstep(action, timeout_s=...)sets the limit of one step. AMirageActionhas no limit without either. ACallToolActionwithout either gets OpenEnv’s MCP default of 30 seconds. A limit that is zero, negative or not finite raisesValueError.
MCP
step() also takes OpenEnv’s ListToolsAction and CallToolAction. They reach the episode’s session through Mirage’s MCP server in process, which serves the seven tools and every VFS call as a vfs_<call> tool, such as vfs_stat and vfs_readdir. A tool call counts as a step and gets a reward. Listing the tools does not.
An MCP client that the OpenEnv server holds open, such as env.mcp_session(), follows the episode across resets.
A trainer that uses OpenEnv’s MCPToolClient gets a tool’s text back from call_tool(), as it would from a FastMCP tool that returns a string, and a failed call raises RuntimeError. Calls that come in on the server’s /mcp JSON-RPC route reach the tools without going through step(), so they get no reward, done or step count.
To use a workspace that a Mirage server holds, point MirageServerEnv at its /v1/workspaces/{id}/mcp endpoint:
reset() starts a new step count and rubric trajectory, but the files stay as they are. mirage_server_transport() returns the same endpoint as a FastMCP transport.
Serve it
OpenEnv’screate_app serves the environment to trainers over HTTP and WebSocket. Each WebSocket session gets its own MirageOpenEnv, and so its own episode workspace:
MCPToolClient, pass CallToolAction and CallToolObservation instead of MirageAction and MirageObservation.
Sync and async
The async methodsreset_async, step_async and aclose do the work. reset, step and close run them on one event loop that the environment owns, and refuse to run on that loop: inside async code, await the async method. close() and aclose() close the episode’s workspace and leave the base workspace open for its owner. After that, reset and step raise RuntimeError.
Exports
Examples
openenv_example.pyruns two episodes over one base workspace, with a reward hook, a policy refusal and MCP tool calls.