Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3d3ffd8
feat(task-steps): computer_exec, a command run inside a computer thro…
williamloo-scale Nov 19, 2026
6bae0c0
feat(verifiers): cua_verifier, a computer-use task's rubric graded on…
williamloo-scale Nov 19, 2026
9f8ff02
fix(verifiers): cua_verifier bounds what it renders, marks cut state …
williamloo-scale Nov 19, 2026
0246f2b
fix(verifiers): cua_verifier renders each file in a memory- and time-…
williamloo-scale Nov 19, 2026
7484f69
fix(verifiers): a cancelled cua_verifier rendering kills its process
williamloo-scale Nov 19, 2026
b337d7b
Merge main into wloo/cua-verifier
earakely-scale Nov 20, 2026
494dee9
fix(verifiers): aggregate_verifiers refuses a gated entry, whose gate…
earakely-scale Nov 20, 2026
d5906e5
refactor(verifiers): cua_verifier becomes computer_verifier, in verif…
earakely-scale Nov 20, 2026
d9c5f5c
Merge main into wloo/cua-verifier
earakely-scale Nov 20, 2026
518aafc
Merge main into wloo/cua-verifier
earakely-scale Nov 23, 2026
953719a
refactor(verifiers): computer_verifier scores as rubrics_verifier doe…
earakely-scale Nov 23, 2026
de227f6
refactor(verifiers): computer_verifier grades the agent's response wi…
earakely-scale Nov 23, 2026
1a37d4b
test(verifiers): computer_verifier's minimal step names its prompt_id
earakely-scale Nov 23, 2026
123fc5f
refactor(verifiers): computer_verifier reads files and state through …
earakely-scale Nov 23, 2026
4f21e70
test(verifiers): computer_verifier's shared test step names its resul…
earakely-scale Nov 23, 2026
3f917ab
fix(verifiers): computer_verifier bounds what an export reads, and re…
earakely-scale Nov 23, 2026
1058450
fix(verifiers): computer_verifier records where each export it upload…
earakely-scale Nov 23, 2026
f7749b8
fix(verifiers): computer_verifier reads an inline export only up to a…
earakely-scale Nov 23, 2026
3b9cf1c
feat(computer): snapshot a multi env's computer; grade with a judge f…
earakely-scale Nov 24, 2026
cd12948
Merge remote-tracking branch 'origin/main' into edgar/pr772-main3
earakely-scale Nov 24, 2026
b7f1273
test(computer): read the judge's staged files in its container
earakely-scale Nov 24, 2026
4216363
refactor(computer): name a multi env's computer by computer_name
earakely-scale Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 19 additions & 55 deletions src/agent_env/task_step/task_steps/computer/computer_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
from agentenv_protocol.computer import COMPUTER, COMPUTER_EXEC

from agent_env.entity.refs import EntityRef
from agent_env.env.env import DeployedEnv, DeployedSandboxEnv
from agent_env.env.envs.computer.env import ComputerEnv
from agent_env.env.env import DeployedSandboxEnv
from agent_env.env.envs.computer.utils import inside
from agent_env.env.envs.computer.utils.sites import RootChannel
from agent_env.env.envs.multi_env import MultiEnv
from agent_env.providers.sandbox_providers.sandbox_provider import build_sandbox_provider
from agent_env.task_step.context import TaskStepContext
from agent_env.task_step.preflight import stored_env
from agent_env.task_step.task_step import TaskStep, TaskStepDependency
from agent_env.task_step.task_steps.computer.lookup import computer_problem, find_computer

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -101,8 +100,9 @@ def background_script() -> str:
class ComputerExecTaskStep(TaskStep):
"""Run ``command`` inside the computer of the env ``env_id`` as its session user, in ``cwd`` (relative to the home,
the home by default), with ``env`` added to its environment, for at most ``timeout_s``. ``command`` is a program and
its arguments, or a string run by ``sh -c``. For a multi env, ``computer`` names the computer, by its environment
name, and may be left out when the env has one.
its arguments, or a string run by ``sh -c``. For a multi env, ``computer_name`` names the computer by its
environment name there (its key in the deploy's ``child_envs``, not its env id), and may be left out when the env
has one.

With ``scope: "system"`` it runs as root instead, through the computer's sandbox rather than its driver, in the
same folder and with the session user's ``HOME``; a computer booted from a disk has no such route.
Expand All @@ -118,14 +118,14 @@ class ComputerExecTaskStep(TaskStep):
entity_refs = (EntityRef.env("env_id"),)

def __init__(self, id: str, version: Optional[int], env_id: str, command: Command,
computer: Optional[str] = None, cwd: Optional[str] = None, env: Optional[dict[str, str]] = None,
computer_name: Optional[str] = None, cwd: Optional[str] = None, env: Optional[dict[str, str]] = None,
timeout_s: float = DEFAULT_TIMEOUT_S, background: bool = False, check: bool = True,
scope: str = "session", depends_on: Optional[list[TaskStepDependency]] = None,
fail_task_on_error: bool = True):
super().__init__(id, version, depends_on=depends_on, fail_task_on_error=fail_task_on_error)
self.env_id = env_id
self.command = command
self.computer = computer
self.computer_name = computer_name
self.cwd = cwd
self.env = env
self.timeout_s = timeout_s
Expand All @@ -142,8 +142,8 @@ def config_problems(self) -> list[str]:
problems.append(f"step {self.id!r}: command must not be blank")
elif not (isinstance(self.command, list) and self.command and all(isinstance(a, str) for a in self.command)):
problems.append(f"step {self.id!r}: command must be a non-empty list of strings, or a string run by sh -c")
if self.computer is not None and (not isinstance(self.computer, str) or not self.computer):
problems.append(f"step {self.id!r}: computer, when given, must be a non-empty string")
if self.computer_name is not None and (not isinstance(self.computer_name, str) or not self.computer_name):
problems.append(f"step {self.id!r}: computer_name, when given, must be a non-empty string")
if self.cwd is not None and (not isinstance(self.cwd, str) or self.cwd.startswith("/")):
problems.append(f"step {self.id!r}: cwd is a folder relative to the session user's home, not {self.cwd!r}")
if self.env is not None and not (isinstance(self.env, dict) and all(
Expand Down Expand Up @@ -171,21 +171,22 @@ def preflight(self) -> list[str]:
problems = super().preflight()
if not isinstance(self.env_id, str) or not self.env_id or (env := stored_env(self.env_id)) is None:
return problems
if problem := _computer_problem(env, self.computer):
if problem := computer_problem(env, self.computer_name):
problems.append(f"step {self.id!r}: {problem}")
return problems

def to_dict(self) -> dict:
return {**super().to_dict(), "env_id": self.env_id, "command": self.command, "computer": self.computer,
"cwd": self.cwd, "env": self.env, "timeout_s": self.timeout_s, "background": self.background,
"check": self.check, "scope": self.scope}
return {**super().to_dict(), "env_id": self.env_id, "command": self.command,
"computer_name": self.computer_name, "cwd": self.cwd, "env": self.env, "timeout_s": self.timeout_s,
"background": self.background, "check": self.check, "scope": self.scope}

@classmethod
def from_dict(cls, data: dict) -> ComputerExecTaskStep:
return cls(**cls._base_from_dict(data), env_id=data["env_id"], command=data["command"],
computer=data.get("computer"), cwd=data.get("cwd"), env=data.get("env"),
timeout_s=data.get("timeout_s", DEFAULT_TIMEOUT_S), background=data.get("background", False),
check=data.get("check", True), scope=data.get("scope", "session"))
computer_name=data.get("computer_name", data.get("computer")), cwd=data.get("cwd"),
env=data.get("env"), timeout_s=data.get("timeout_s", DEFAULT_TIMEOUT_S),
background=data.get("background", False), check=data.get("check", True),
scope=data.get("scope", "session"))

def command_argv(self) -> list[str]:
"""The command as a program and its arguments: through ``sh -c`` when it's a string."""
Expand All @@ -197,7 +198,7 @@ def argv(self) -> list[str]:
return ["sh", "-c", background_script(), "computer_exec", *argv] if self.background else argv

async def execute(self, context: TaskStepContext) -> TaskStepContext:
deployed = find_computer(context, self.env_id, self.computer)
deployed = find_computer(context, self.env_id, self.computer_name)
if missing := [m for m in inside.missing(deployed) if m.startswith(COMPUTER_EXEC)]:
raise RuntimeError(f"{self.type} {self.id!r}: env {self.env_id!r}'s computer serves no {missing[0]}")
if self.timeout_s > (limit := inside.max_timeout_s(deployed)):
Expand All @@ -212,7 +213,7 @@ async def execute(self, context: TaskStepContext) -> TaskStepContext:
answer = await self._as_root(deployed, argv)
else:
answer = await inside.run(deployed, argv, timeout_s=self.timeout_s, env=self.env, cwd=self.cwd)
record = {"env_id": self.env_id, "computer": self.computer, "argv": argv, "scope": self.scope,
record = {"env_id": self.env_id, "computer_name": self.computer_name, "argv": argv, "scope": self.scope,
"background": self.background,
"exit_code": answer.get("exit_code"), "timed_out": bool(answer.get("timed_out")),
"truncated": bool(answer.get("truncated")),
Expand Down Expand Up @@ -259,43 +260,6 @@ async def _as_root(self, deployed: DeployedSandboxEnv, argv: list[str]) -> dict:
"stdout": out.decode("utf-8", errors="replace"), "stderr": err.decode("utf-8", errors="replace")}


def find_computer(context: TaskStepContext, env_id: str, computer: Optional[str]) -> DeployedSandboxEnv:
"""The deploy record of the computer in ``env_id`` that serves computer-exec/v1 ``run``: the env's own, or one of a
multi env's computers' (``DeployedGatewayEnv.child_envs``), the one ``computer`` names else its only one."""
deployed = next((d for d in context.deployed_envs if d.env_id == env_id), None)
if deployed is None:
raise RuntimeError(f"env {env_id!r} isn't in context.deployed_envs")
children = {name: DeployedEnv.from_dict(data)
for name, data in (getattr(deployed, "child_envs", None) or {}).items()}
if computer is not None:
found = children.get(computer)
if found is None:
raise RuntimeError(f"env {env_id!r} has no computer named {computer!r} (it has {sorted(children)})")
return found
if deployed.supports(COMPUTER_EXEC, "run"):
return deployed
computers = [record for record in children.values() if record.supports(COMPUTER_EXEC, "run")]
if len(computers) != 1:
raise RuntimeError(f"env {env_id!r} has {len(computers) or 'no'} computers serving {COMPUTER_EXEC} run"
+ (f": name one as computer, of {sorted(children)}" if computers else ""))
return computers[0]


def _computer_problem(env: object, computer: Optional[str]) -> Optional[str]:
if isinstance(env, ComputerEnv):
return None if computer is None else f"env {env.id!r} is a computer env, so it takes no computer name"
if not isinstance(env, MultiEnv):
return f"env {getattr(env, 'id', '?')!r} is no computer env, nor a multi env with one"
browser = env.website_browser().computer
names = [computer_env.environment_name for computer_env in (*env.computer_envs, *([browser] if browser else []))]
if computer is not None and computer not in names:
return f"env {env.id!r} has no computer named {computer!r} (it has {names})"
if computer is None and len(names) != 1:
return (f"env {env.id!r} has {len(names) or 'no'} computers" +
(f": name one as computer, of {names}" if names else ""))
return None


def _os(deployed: DeployedSandboxEnv) -> Optional[str]:
"""The computer's OS, as its card's computer/v1 platform says."""
return (protocol_v1.extension_params(deployed.environment_card or {}, COMPUTER).get("platform") or {}).get("os")
Expand Down
58 changes: 58 additions & 0 deletions src/agent_env/task_step/task_steps/computer/lookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Finding a computer in an env, for the steps that reach inside one: its deploy record in a run, by its name in a multi
env or as the only computer there, and whether a stored env has it."""

from __future__ import annotations

from typing import Optional

from agentenv_protocol.computer import COMPUTER_EXEC

from agent_env.env.env import DeployedEnv, DeployedSandboxEnv
from agent_env.env.envs.computer.env import ComputerEnv
from agent_env.env.envs.multi_env import MultiEnv
from agent_env.task_step.context import TaskStepContext


def find_computer(context: TaskStepContext, env_id: str, computer_name: Optional[str]) -> DeployedSandboxEnv:
"""The deploy record of the computer in ``env_id`` that serves computer-exec/v1 ``run``: the env's own, or one of a
multi env's computers' (``child_computer``)."""
deployed = next((d for d in context.deployed_envs if d.env_id == env_id), None)
if deployed is None:
raise RuntimeError(f"env {env_id!r} isn't in context.deployed_envs")
if computer_name is None and deployed.supports(COMPUTER_EXEC, "run"):
return deployed
return child_computer(deployed, computer_name)[1]


def child_computer(deployed: DeployedEnv, computer_name: Optional[str]) -> tuple[str, DeployedSandboxEnv]:
"""A multi env's computer in its deployment (``DeployedGatewayEnv.child_envs``, keyed by each computer's
environment name), by that name and with its deploy record: the one ``computer_name`` names, else its only one
serving computer-exec/v1 ``run``."""
children = {name: DeployedEnv.from_dict(data)
for name, data in (getattr(deployed, "child_envs", None) or {}).items()}
if computer_name is not None:
found = children.get(computer_name)
if found is None:
raise RuntimeError(f"env {deployed.env_id!r} has no computer named {computer_name!r} "
f"(it has {sorted(children)})")
return computer_name, found
computers = [(name, record) for name, record in children.items() if record.supports(COMPUTER_EXEC, "run")]
if len(computers) != 1:
raise RuntimeError(f"env {deployed.env_id!r} has {len(computers) or 'no'} computers serving {COMPUTER_EXEC} run"
+ (f": name one as computer_name, of {sorted(children)}" if computers else ""))
return computers[0]


def computer_problem(env: object, computer_name: Optional[str]) -> Optional[str]:
if isinstance(env, ComputerEnv):
return None if computer_name is None else f"env {env.id!r} is a computer env, so it takes no computer_name"
if not isinstance(env, MultiEnv):
return f"env {getattr(env, 'id', '?')!r} is no computer env, nor a multi env with one"
browser = env.website_browser().computer
names = [computer_env.environment_name for computer_env in (*env.computer_envs, *([browser] if browser else []))]
if computer_name is not None and computer_name not in names:
return f"env {env.id!r} has no computer named {computer_name!r} (it has {names})"
if computer_name is None and len(names) != 1:
return (f"env {env.id!r} has {len(names) or 'no'} computers" +
(f": name one as computer_name, of {names}" if names else ""))
return None
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""snapshot_computer_env: a computer env's files, kept by their paths in its environment artifact, and each of its apps'
exports in theirs, which load_artifact loads back into a computer."""
"""snapshot_computer_env: a computer's files, kept by their paths in its environment artifact, and each of its apps'
exports in theirs, beside a multi env's other environments, which load_artifact loads back into a computer or stages
as files for a judge."""

from __future__ import annotations

Expand All @@ -10,23 +11,27 @@
from pydantic import TypeAdapter, ValidationError

from agent_env.entity.refs import EntityRef, RefRole
from agent_env.env.env import Env
from agent_env.env.envs.computer.env import ComputerEnv
from agent_env.env.env import Env, gateway_url_of
from agent_env.env.envs.multi_env import MultiEnv
from agent_env.store.ids import is_local_id, validate_local_id
from agent_env.task_step.context import TaskStepContext
from agent_env.task_step.preflight import stored_env
from agent_env.task_step.task_step import TaskStep, TaskStepDependency
from agent_env.task_step.task_steps.computer.lookup import child_computer, computer_problem
from agent_env.task_step.task_steps.snapshot_env import DEFAULT_EXPORT_TIMEOUT_SECONDS, SnapshotEnvTaskStep

_PATHS = TypeAdapter(list[RelativePath])


class SnapshotComputerEnvTaskStep(SnapshotEnvTaskStep):
"""Snapshot a deployed computer env's files into a new environment universe, as ``snapshot_env`` snapshots an env,
"""Snapshot a deployed computer's files into a new environment universe, as ``snapshot_env`` snapshots an env,
each file under its path relative to the session user's home in the computer's environment artifact: those under
``file_paths``, by default the folders its card declares, leaving out each app's paths. Each app that exports is
kept beside it in an environment artifact under the app's name. ``load_artifact`` loads the snapshot back into a
computer, through ``data/add``.
kept beside it in an environment artifact under the app's name. The computer is a computer env, or the one
``computer_name`` names in a multi env by its environment name there (its key in the deploy's ``child_envs``, not
its env id; the env's only computer when unnamed), whose other environments are kept beside it as ``snapshot_env``
keeps them. ``load_artifact`` loads the snapshot back into a computer, through ``data/add``, or
stages it as files in an agent, a judge's sandbox for one.

Output: ``context.metadata["env_snapshotted_universes"][self.id]`` = ``{"id", "version"}``."""

Expand All @@ -44,6 +49,7 @@ def __init__(
env_instance_id: Optional[str] = None,
env_step_id: Optional[str] = None,
snapshot_id: Optional[str] = None,
computer_name: Optional[str] = None,
file_paths: Optional[list[str]] = None,
export_timeout_seconds: int = DEFAULT_EXPORT_TIMEOUT_SECONDS,
depends_on: Optional[list[TaskStepDependency]] = None,
Expand All @@ -52,18 +58,20 @@ def __init__(
super().__init__(id, version, env_id=env_id, env_instance_id=env_instance_id, env_step_id=env_step_id,
snapshot_id=snapshot_id, export_timeout_seconds=export_timeout_seconds,
depends_on=depends_on, fail_task_on_error=fail_task_on_error)
self.computer_name = computer_name
self.file_paths = file_paths

def to_dict(self) -> dict:
return {**TaskStep.to_dict(self), "env_id": self.env_id, "env_instance_id": self.env_instance_id,
"env_step_id": self.env_step_id, "snapshot_id": self.snapshot_id, "file_paths": self.file_paths,
"env_step_id": self.env_step_id, "snapshot_id": self.snapshot_id, "computer_name": self.computer_name,
"file_paths": self.file_paths,
"export_timeout_seconds": self.export_timeout_seconds}

@classmethod
def from_dict(cls, data: dict) -> SnapshotComputerEnvTaskStep:
return cls(**cls._base_from_dict(data), env_id=data.get("env_id"), env_instance_id=data.get("env_instance_id"),
env_step_id=data.get("env_step_id"), snapshot_id=data.get("snapshot_id"),
file_paths=data.get("file_paths"),
computer_name=data.get("computer_name"), file_paths=data.get("file_paths"),
export_timeout_seconds=data.get("export_timeout_seconds", DEFAULT_EXPORT_TIMEOUT_SECONDS))

def config_problems(self) -> list[str]:
Expand All @@ -77,31 +85,33 @@ def config_problems(self) -> list[str]:
return problems

def preflight(self) -> list[str]:
"""The env this step names when it isn't a computer env."""
"""The env this step names when it isn't a computer env, nor a multi env with the computer
``computer_name`` picks."""
problems = super().preflight()
if self.env_id is None:
return problems
env = stored_env(self.env_id)
if env is None: # what the run reports
return problems
return problems if isinstance(env, ComputerEnv) else [*problems, _not_a_computer(env)]
problem = computer_problem(env, self.computer_name)
return [*problems, f"snapshot_computer_env {self.id!r}: {problem}"] if problem else problems

async def execute(self, context: TaskStepContext) -> TaskStepContext:
snapshot_id = self._derive_snapshot_id(context)
if is_local_id(snapshot_id):
validate_local_id(snapshot_id)
deployed = self._resolve_deployed_env(context)
env = await asyncio.to_thread(Env.get, deployed.env_id, deployed.env_version)
if not isinstance(env, ComputerEnv):
raise RuntimeError(_not_a_computer(env))
if isinstance(env, MultiEnv):
name = child_computer(deployed, self.computer_name)[0]
elif problem := computer_problem(env, self.computer_name):
raise RuntimeError(f"snapshot_computer_env {self.id!r}: {problem}")
else:
name = env.computer_name
result = await self.snapshot_env_state(
env=env, gateway_url=None, snapshot_id=snapshot_id, deployed=deployed,
env=env, gateway_url=gateway_url_of(deployed), snapshot_id=snapshot_id, deployed=deployed,
export_timeout_seconds=self.export_timeout_seconds,
data_get_params=None if self.file_paths is None else {env.computer_name: {"paths": self.file_paths}})
data_get_params=None if self.file_paths is None else {name: {"paths": self.file_paths}})
context.metadata.setdefault("env_snapshotted_universes", {})[self.id] = {
"id": result.environment_universe_artifact_id, "version": result.environment_universe_artifact_version}
return context


def _not_a_computer(env: Env) -> str:
return f"snapshot_computer_env snapshots a computer env, and {env.id} is a {env.type} env"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
item,amount
rent,1200
food,300
total,1500
Loading
Loading