Repository navigation
fix(sandbox): steps that target a reattached local agent run in its container - #37
Merged
earakely-scale merged 1 commit intoOct 1, 2026
Conversation
…ontainer LocalSandboxProvider.get_sandbox restored mode=container from the .agent-container-mode marker. verify_sandbox, collect_artifacts and run_code read that as "exec runs inside the runtime", but LocalSandbox.exec runs on the host. Probes, collection and scripts aimed at the agent ran on the host instead. A reattached local sandbox now stays VM mode, so those steps take their existing `docker exec <container>` path. Ownership is read from the marker as LocalSandbox.owns_container. Container discovery uses it: an owned container that is not running raises, rather than falling back to another run's a2a-agent-* container on the shared Docker host. terminate is unchanged and still removes the container. The local-agent integration tests skip as a declared capability gap when no Docker daemon is running. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
@greptileai review |
earakely-scale
deleted the
edgararakelyan/reattached-agent-container-steps
branch
October 1, 2026 19:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
On the local backend,
verify_sandbox,collect_artifactsandrun_codenow run inside the container of the agent they target (agent_name). Before this change they ran on the host.LocalSandboxProvider.get_sandboxno longer turns the.agent-container-modemarker intomode=container. A reattached agent sandbox staysvm, so the three steps take their existingdocker exec <container>path.LocalSandbox.execalready strips the argvsudo.LocalSandbox.owns_containerreads the marker.terminateis unchanged: it still removescontainer_name, andteardown_runstill removes the work dir._discover_container(inverify_sandboxandcollect_artifacts) raisesAgent container '<name>' is not running. It no longer falls back to ana2a-agent-*container, which on a shared Docker host belongs to another run.agentenv-capability-missing: docker_daemon).Why
These steps treated
mode=containeras meaning that exec runs inside the runtime, butLocalSandbox.execruns on the host. On a reattached local agent that meant:probe_file_exists /etc/debian_versionscored 0 on an agent that had the file, and a check of a file that exists only on the host scored 1;bash_cmd_succeedsran the task's bash on the developer's machine;run_coderan the script on the host, which crashes on macOS, where there is no GNUtimeout;collect_artifactsran BSDfind -printfon macOS and failed. On a Linux host it would have read host files.load_artifactwas already correct, because it writes intocontainer_namefor anyVmSandbox.Testing
Where this was tested. Every row ran against this branch and passed. The
mainrows are controls.main: 5752 passed). The 8 new tests fail onmaintest_verify_sandbox_local.py, real containersmainagent-env task runmain(control)collect_artifactsfailskill -9mid-step, then a resumeUnit. New or updated tests:
get_sandboxmode and ownership, with and without the marker;terminateafter a reattach runs onlydocker rm -f <container>;teardown_runon a reattached local agent removes the container and the work dir;verify_sandbox,collect_artifactsandrun_codebuild for a reattached local agent;a2a-agent-other.Against
main'ssrc, 8 of them fail. Theteardown_runtest passes on both, since it guards existing behavior.Integration (fast tier). Two tests in
tst/integration/task_step/test_verify_sandbox_local.pystart a real container throughLocalSandboxProvider.create_container. They usemirror.gcr.io/library/nginx:1.27-bookworm, which is public, multi-arch and has a Debian userland. The container is recorded as a deployed agent, so no model or registered agent is needed.verify_sandboxwithagent_namesees a file that exists only in the container, anduname -sisLinux.collect_artifactscollects a file written inside the container, byte for byte.With
main'ssrc, the 2 new tests fail ([False, False], andproduced no file_artifact_universe), and the 2 existing tests pass.E2E on Rancher Desktop (macOS, arm64). The echo agent from
tst/data/a2a_agentwas built for the host and pushed to the local registry under a test prefix. It ran throughagent-env task runwith isolated XDG and sandbox directories and a placeholder model key. The steps weredeploy_agent→load_artifactinto the agent (/work/artifact) →run_code→verify_sandbox(in-container) →verify_sandbox(host-only control) →collect_artifacts./etc/debian_version, the loaded file and the filerun_codewrote were all present, anduname -swasLinux.test -d /Usersfailed.run_coderan in the container. It reportedsysname=Linux,cwd=/appand a hostname equal to the container's.docker exec … catread in the container, byte for byte./tmp/agent_env_run_code*, and the work dir held only.agent-container-mode.teardown_runon the context JSONtask runwrote, removed the container and the work dir.Control on
main. The same task withoutrun_code, which crashes on a macOS host onmain, scored 0.0 on the in-container verifier and 1.0 on the host-only one.collect_artifactsfailed withresolved 1 artifact path(s) but produced no file_artifact_universe.Chaos.
a2a-agent-*container held the same files throughout, so a fallback would have passed.verify_sandboxandcollect_artifactsraisedAgent container 'agent-local-…' is not runningand listed the running containers.run_codereportedcontainer … is not running, thenNo such container. None scored, and none fell back to the host or to the decoy.kill -9of the CLI mid-step. The kill landed during a 45 srun_code. The agent container stayed up, and so did the orphaneddocker exec.task run --start-step 2 --context-json …then ranrun_code,verify_sandbox(1.0) andcollect_artifactsinside the same container. Teardown removed the container, the orphaneddocker execand the work dir.Not in this PR
/appon a local agent. The e2e loads into/work/artifact. This PR doesn't change howload_artifacttreats/app/...destinations on a local agent.A2AAgentValidator._discover_agent_container. It has the samea2a-agent-*fallback. It now takes the VM path on local too, and finds its own container while that container is running.🤖 Generated with Claude Code
The PR appears safe to merge; no outstanding finding was established.
What we checked:
Summary
The PR fixes where steps run when they target a reattached local agent. They now use that agent’s container, and verification and artifact collection stop if its owned container is missing instead of choosing another one.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Reattach local agent] --> B[VM-mode sandbox] B --> C{Owned container running?} C -->|Yes| D[Run step with docker exec] C -->|No| E[Stop with an error]Reviews (2) · Last reviewed commit: "fix(sandbox): steps that target a reatta..."