Skip to content

Predefined Environment Resources

PythonSandboxEnv(container: Any, resource_id: str, spec: ContainerResourceSpec)

Bases: ContainerResource

ContainerResource that talks to the Python HTTP env image via /health and /exec. Expects the container to be started by the runner with port mapping; start() connects the httpx client and waits for /health.

Functions

step(code: str) -> str async

Execute code via HTTP POST /exec. Returns output or detail string.

ALFWorldEnv(container: Any, resource_id: str, spec: ContainerResourceSpec)

Bases: ContainerResource

ContainerResource for ALFWorld. Runner starts the container; start() connects and waits for /health. Use via Context.acquire_resource(spec=ALFWorldSpec, scope="rollout", backend="local").

ScienceWorldEnv(container: Any, resource_id: str, spec: ContainerResourceSpec)

Bases: ContainerResource

Container-backed ScienceWorld environment resource.

This class extends :class:ContainerResource and provides an HTTP-based interaction layer to a ScienceWorld server running inside the container. The resource lifecycle is:

  1. Container is started by the resource runner.
  2. :meth:start resolves mapped host port and waits for /health.
  3. :meth:reset loads a task variation and resets episode state.
  4. :meth:step executes environment actions and tracks max score.

Use this resource through context acquisition (not direct construction): await context.acquire_resource(spec=ScienceWorldSpec, scope="rollout", backend="local").

Parameters:

  • container (Any) –

    Backend container handle created by the resource runner.

  • resource_id (str) –

    Unique id used by the resource engine.

  • spec (ContainerResourceSpec) –

    Resource configuration containing image/port/start options.

Attributes

category: str property

Resource category identifier used by the resource engine.

Functions

start() -> None async

Start base container resource, connect client, and warm-load a default task.

reset(env_args: Any = None) -> str async

Load a task variation and reset environment state.

Parameters:

  • env_args (Any, default: None ) –

    Optional dict with task_name and variation_idx.

Returns:

  • str –

    The initial observation string after loading/resetting the task.

step(action: str) -> Union[str, dict] async

Execute an action in ScienceWorld or return terminal reward info.

Parameters:

  • action (str) –

    ScienceWorld action string, or "get_reward" to query the tracked max score-based reward.

Returns:

  • Union[str, dict] –

    Observation string for normal actions, or a dict containing

  • Union[str, dict] –

    observation and reward for "get_reward".

end() -> None async

Close HTTP client and terminate the underlying container resource.

WebShopEnv(container: Any, resource_id: str, spec: ContainerResourceSpec)

Bases: ContainerResource

ContainerResource for WebShop text environment. Runner starts the container; start() connects and loads home. Use via Context.acquire_resource(spec=WebShopSpec, scope="rollout", backend="local").

Attributes

observation property

Compiles state into either the html, text, text_rich, or url observation mode.

Returns:

  • str –

    The current observation in the selected mode.

Functions

reset(env_args=None) -> str async

Reset the environment to its initial state or to a specific task_id if provided.

Parameters:

  • env_args (dict, default: None ) –

    Dictionary that may contain 'task_id'. Default is None. Used during training.

Returns:

  • str ( str ) –

    None (kept for compatibility)

step(action: str, task_id: int = None) -> str async

Take an action in the environment and return the observation.

Parameters:

  • action (str) –

    An action in the form of 'click[value]' or 'search[keywords]'.

  • task_id (int, default: None ) –

    Task identifier for reward calculation.

Returns:

  • str –

    str or dict: The observation after the action, and reward if applicable.

end() -> None async

Release client and clear state; container is released by the resource engine.

get_available_actions()

Returns list of available actions at the current step. Scans the current HTML for clickable elements and search bar.

Returns:

  • dict –

    { 'has_search_bar': bool, 'clickables': list of str }

get_instruction_text()

Get corresponding instruction text for current environment session.

Returns:

  • str –

    The instruction text from the HTML.

convert_html_to_text(html, simple=True)

Strip HTML of tags and add separators to convert observation into simple or rich text mode.

Parameters:

  • html (str) –

    HTML string to convert.

  • simple (bool, default: True ) –

    If True, use simple [SEP] separators. If False, use rich formatting.

Returns:

  • str –

    The converted text observation.

tag_visible(element) staticmethod

Determine if a tag is visible (not style/script/head/title/meta/document/comment).

Parameters:

  • element –

    BeautifulSoup element.

Returns:

  • bool –

    True if visible, False otherwise.

acquire() async staticmethod

Acquire and start a new WebAgentTextEnv environment asynchronously.

Returns:

  • WebAgentTextEnv –

    The started environment instance.

parse_action(action) staticmethod

Parse action string to action name and its arguments.

Parameters:

  • action (str) –

    Action string, e.g., 'click[value]' or 'search[keywords]'.

Returns:

  • tuple –

    (action_name, action_arg)