Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion AGENTS.md

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions src/agent_env/env/envs/computer/utils/inside.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ async def read_file(deployed: DeployedSandboxEnv, path: str) -> bytes:


async def run(deployed: DeployedSandboxEnv, argv: list[str], *, timeout_s: float,
env: Optional[dict[str, str]] = None) -> dict:
"""computer-exec/v1 ``run``'s answer for ``argv``, under a request id of its own. A call whose connection breaks
fails rather than being sent again: a driver that restarted would run the command a second time, beside the first,
which outlives the driver that started it."""
params = {"argv": argv, "request_id": uuid.uuid4().hex, "timeout_s": timeout_s, **({"env": env} if env else {})}
env: Optional[dict[str, str]] = None, cwd: Optional[str] = None) -> dict:
"""computer-exec/v1 ``run``'s answer for ``argv``, in ``cwd`` relative to the home, the home by default, under a
request id of its own. A call whose connection breaks fails rather than being sent again: a driver that restarted
would run the command a second time, beside the first, which outlives the driver that started it."""
params = {"argv": argv, "request_id": uuid.uuid4().hex, "timeout_s": timeout_s, **({"env": env} if env else {}),
**({"cwd": cwd} if cwd else {})}
try:
return await deployed.invoke(COMPUTER_EXEC, "run", params, timeout=timeout_s + CALL_MARGIN_S)
except httpx.TransportError as e:
Expand Down
18 changes: 15 additions & 3 deletions src/agent_env/env/envs/computer/utils/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,25 @@ async def run(self, argv: list[str]) -> str:
if isinstance(self.sandbox, VmSandbox):
return await self.sandbox.exec_script(f"docker exec -u 0 {shlex.quote(self.sandbox.container_name)} "
f"{shlex.join(argv)}")
await self._check_root()
return await self._exec(argv)

async def exec(self, argv: list[str]) -> tuple[int, str, str]:
"""``argv`` run as root: its exit code, stdout and stderr, whatever the code."""
if isinstance(self.sandbox, VmSandbox):
return await self.sandbox.exec_with_output(
"sudo", "bash", "-c", f"docker exec -u 0 {shlex.quote(self.sandbox.container_name)} {shlex.join(argv)}")
await self._check_root()
return await self.sandbox.exec_with_output(*argv)

async def _check_root(self) -> None:
if not self.checked:
uid = (await self._exec(["id", "-u"])).strip()
if uid != "0":
raise RuntimeError(f"site routing installs as root, and the {getattr(self.sandbox, 'type', 'given')} "
f"sandbox runs the computer's commands as uid {uid}; deploy it on a VM sandbox")
raise RuntimeError(f"root in the computer runs through its sandbox, and the "
f"{getattr(self.sandbox, 'type', 'given')} sandbox runs the computer's commands as "
f"uid {uid}; deploy it on a VM sandbox")
self.checked = True
return await self._exec(argv)

async def _exec(self, argv: list[str]) -> str:
code, stdout, stderr = await self.sandbox.exec_with_output(*argv)
Expand Down
2 changes: 1 addition & 1 deletion src/agent_env/task/episode/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _rubrics_verifier(step: RubricsVerifierTaskStep, outside: Outside) -> list[s
"aggregate_verifiers", "apply_server_config", "browser_activate_tab", "browser_clear_local_storage",
"browser_close_tab", "browser_delete_cookies", "browser_lease_context", "browser_open_tab",
"browser_release_context", "browser_set_cookies", "browser_sign_in", "browser_set_local_storage", "build_mcp_cli",
"combine_universe_verdicts", "configure_scheduled_checks", "deploy_env", "deploy_sandbox", "end_browser_recording",
"combine_universe_verdicts", "computer_exec", "configure_scheduled_checks", "deploy_env", "deploy_sandbox", "end_browser_recording",
"end_computer_recording", "start_browser_recording", "start_computer_recording", "env_outcome_verifier",
"modify_env_tool_access", "reset_env", "review", "user_sim_judge",
"run_container_unit_tests_verifier", "run_docker_container", "set_env_clock_rate", "snapshot_env", "snapshot_computer_env",
Expand Down
2 changes: 2 additions & 0 deletions src/agent_env/task_step/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def _builtin_registry() -> dict[str, type["TaskStep"]]:
from agent_env.task_step.task_steps.snapshot_agent_state import SnapshotAgentStateTaskStep
from agent_env.task_step.task_steps.snapshot_env import SnapshotEnvTaskStep
from agent_env.task_step.task_steps.computer.snapshot_computer_env import SnapshotComputerEnvTaskStep
from agent_env.task_step.task_steps.computer.computer_exec import ComputerExecTaskStep
from agent_env.task_step.task_steps.peer_agents import PeerAgentsTaskStep
from agent_env.task_step.task_steps.verifiers.verify_sandbox import VerifySandboxTaskStep
from agent_env.task_step.task_steps.verifiers.aggregate_verifiers import AggregateVerifiersTaskStep
Expand Down Expand Up @@ -175,6 +176,7 @@ def _builtin_registry() -> dict[str, type["TaskStep"]]:
_get_type(SnapshotAgentStateTaskStep): SnapshotAgentStateTaskStep,
_get_type(SnapshotEnvTaskStep): SnapshotEnvTaskStep,
_get_type(SnapshotComputerEnvTaskStep): SnapshotComputerEnvTaskStep,
_get_type(ComputerExecTaskStep): ComputerExecTaskStep,
_get_type(RunCodeTaskStep): RunCodeTaskStep,
_get_type(PeerAgentsTaskStep): PeerAgentsTaskStep,
_get_type(VerifyA2ASnapshotStep): VerifyA2ASnapshotStep,
Expand Down
Loading
Loading