Skip to content

feat(run_code): run a script on a deploy_sandbox sandbox via sandbox_name - #69

Merged
psinghal20 merged 5 commits into
pratyush/container-sandbox-file-routingfrom
pratyush/run-code-named-sandbox
Oct 6, 2026
Merged

psinghal20 merged 5 commits into
pratyush/container-sandbox-file-routingfrom
pratyush/run-code-named-sandbox

Conversation

@psinghal20

@psinghal20 psinghal20 commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #68. The base is that PR's branch, so this diff is run_code only; it retargets to main once #68 merges.

Summary

run_code could target only an env's VM host (env_id) or an agent container (agent_name). A task that provisions a bare machine with deploy_sandbox, stages files onto it with load_artifact(sandbox_name=...) and collects them with collect_artifacts(sandbox_name=...) had no way to run a script there in between.

  • New sandbox_name target, resolved from context.deployed_sandboxes through the sandbox's own provider type (the lookup load_artifact and collect_artifacts use), deciding from the mode deploy_sandbox recorded:
    • VM-mode sandbox: runs on its host (the existing _HostTarget; staging, run, output read and timeout unchanged);
    • container-mode sandbox: runs in its container via _AgentTarget, the path container-mode agents already use: directly on a container provider, and with a docker exec -u 0 <container> prefix on a VM-backed one, where a plain exec lands on the host.
  • env_id, sandbox_name and agent_name are mutually exclusive: more than one fails at construction (previously env_id silently won over agent_name). A blank value, as a form submits it, is unset.
    • Behaviour change: a host target (env_id or sandbox_name) no longer defaults agent_name, so it serializes agent_name: null. An agent step with no agent_name still runs in DEFAULT_AGENT_NAME.
    • Compatibility: steps stored before this change carry DEFAULT_AGENT_NAME beside env_id; from_dict drops it so they keep loading. A stored step with a non-default agent_name beside env_id is rejected.

Use case

Building a deliverable on a throwaway machine with no env or agent deployed: deploy_sandbox → load_artifact (inputs) → run_code (build) → collect_artifacts (output).

Tests

  • tst/unit/task_step/test_run_code.py: the named sandbox on a VM (host, never docker), its provider type, an unknown name, a container-mode sandbox on a container provider (no prefix) and on a VM-backed one (docker exec -u 0), round trip; exclusivity (every pair and all three, the default agent name beside sandbox_name, blank values unset, host targets store no agent name, no target uses the default agent, legacy stored steps load, a stored non-default agent beside env_id is rejected).
  • tst/integration/task_step/test_run_code_named_sandbox_local.py (new), the chain deploy_sandbox → load_artifact → run_code (zips the inputs, 0600) → collect_artifacts → load_artifact(artifact_from_step_id=...) → run_code (reads the zip back):
    • on a local VM-mode sandbox (no Docker): passes on Linux;
    • on a local container-mode sandbox (Docker + a throwaway registry:2, a non-root image user, paths under /work in the container): passes. Cleanup removes only the containers of sandboxes in the test's own sandbox root.
  • tst/unit + protocol suite with fix(task_steps): reach the container of a container-mode deploy_sandbox sandbox #68 in a python:3.12 slim image: 6084 passed; the same 3 environment failures as on main in that image.
  • check_plugin_api.py: no break to the plugin surface.

Notes for reviewers:

  • On macOS the local VM-mode paths of run_code and collect_artifacts need GNU timeout and stat -c; CI runs Linux.
  • Seen while testing, not changed: collect_artifacts given an absolute artifact_paths entry names the collected member by that absolute path, which load_artifact(artifact_from_step_id=...) then rejects as non-relative. The test collects with base_path and a relative name.

🤖 Generated with Claude Code

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the previous findings are addressed and no new issue was established.

What we checked:

  • Conflicting saved targets: No. The loader can discard an old agent_name, but the constructor rejects two remaining targets.

Summary

Tasks can now use run_code on a sandbox deployed by name, running on its host or inside its container based on the sandbox mode. The step also enforces one execution target at a time while keeping saved host steps loadable.

  • Scripts can now run on a sandbox deployed by name.
  • Run-code steps choose one target and keep saved host steps loadable.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["run_code target"] --> B{"Selected target"}
    B -- env_id --> C["Environment host"]
    B -- sandbox_name --> D{"Deployed sandbox mode"}
    B -- agent_name or default --> E["Agent container"]
    D -- VM --> F["Sandbox host"]
    D -- container --> G["Sandbox container"]
Loading

Reviews (4) · Last reviewed commit: "test(run_code): scope image cleanup to t..."

@psinghal20
psinghal20 requested a review from a team as a code owner October 6, 2026 17:14
Comment thread src/agent_env/task_step/task_steps/run_code.py Outdated
Comment thread tst/integration/task_step/test_run_code_named_sandbox_local.py
…name

run_code could only target an env's VM host (env_id) or an agent container (agent_name), so a
task that provisions a bare machine with deploy_sandbox, stages files onto it with
load_artifact(sandbox_name) and collects them with collect_artifacts(sandbox_name) could not run
a script there in between.

- sandbox_name: resolved from context.deployed_sandboxes through the sandbox's own provider
  type. A VM-mode sandbox runs on its host (the existing host target); a container-mode one runs
  in its container, directly on a container provider and through `docker exec -u 0` on a
  VM-backed one, deciding from the mode deploy_sandbox recorded.
- env_id, sandbox_name and agent_name are mutually exclusive; a blank value is unset. A host
  target no longer defaults agent_name, so it serializes agent_name: null; from_dict drops the
  default agent name older steps stored beside env_id, so they keep loading.
@psinghal20
psinghal20 force-pushed the pratyush/run-code-named-sandbox branch from 9c45e47 to fdb6ae7 Compare October 6, 2026 17:20
psinghal20 and others added 2 commits October 6, 2026 10:30
…routing' into pratyush/run-code-named-sandbox
…n cleanup

Addresses review: each run built a uniquely tagged image that was never removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread tst/integration/task_step/test_run_code_named_sandbox_local.py Outdated
psinghal20 and others added 2 commits October 6, 2026 10:35
…t_name

Addresses review: before the targets were exclusive, env_id overrode any agent_name, so
stored steps with both would now fail to load. Drop the ignored agent_name on load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ners

Addresses review: the ancestor filter could reach another run's containers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@psinghal20
psinghal20 added this pull request to stack #72 October 6, 2026 17:51
@psinghal20
psinghal20 merged commit e124750 into main Oct 6, 2026
13 checks passed
@psinghal20
psinghal20 deleted the pratyush/run-code-named-sandbox branch October 6, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants