Repository navigation
feat(boat): enforce network policies, start from saved snapshots, honor boat's retry waits - #1012
AnicetNgrt wants to merge 1 commit into
Conversation
…or boat's retry waits An allowlist is now the sandbox's boat network policy, sent with the create and enforced on its host before the sandbox is returned. The handle carries the policy boat reports, on create and on reconnect. - network.py: map, validate and read back policies; boat refusals of a policy become NetworkPolicyUnsupportedError so a fallback chain moves on - snapshot config key: every sandbox starts from a boat saved snapshot - create: wait what Retry-After says (up to 120 s), raise at once past that and on trial_compute_limit_reached - downloads go through the host when the policy does not admit the store - create_vm accepts env, as the other VM providers do - boat-sdk 1.15.0, provider README Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
| if exc.status in _REFUSED and error_code(exc) not in _FINAL: | ||
| refusals += 1 | ||
| elif exc.status is not None and exc.status < 500 and error_code(exc) != "idempotency_in_progress": | ||
| raise |
There was a problem hiding this comment.
Failed creates leave sandboxes running
A 429 with trial_compute_limit_reached now reaches the immediate raise, skipping delete_labelled. If an earlier attempt created a sandbox but lost its answer, that sandbox stays running and charging the account until its timeout. Stop retrying by breaking into the existing cleanup path, and add a test for an unanswered attempt followed by this refusal.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agent_env/providers/sandbox_providers/boat/lifecycle.py
Line: 188-191
Comment:
**Failed creates leave sandboxes running**
A `429` with `trial_compute_limit_reached` now reaches the immediate `raise`, skipping `delete_labelled`. If an earlier attempt created a sandbox but lost its answer, that sandbox stays running and charging the account until its timeout. Stop retrying by breaking into the existing cleanup path, and add a test for an unanswered attempt followed by this refusal.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| async def _download_object_to_vm(self, object_url: str, vm_path: str) -> None: | ||
| """Curl a signed URL the network policy admits; send anything else through an upload URL, which needs no | ||
| egress.""" | ||
| object_store = get_config().get_object_store_at(object_url) | ||
| signed = await asyncio.to_thread(object_store.signed_get_url, object_url) | ||
| if self._can_download(signed): | ||
| await self.exec_script(f"curl -fsSL {CURL_RETRY_FLAGS} {shlex.quote(signed)} -o {shlex.quote(vm_path)}") | ||
| return | ||
| await self._write_unsigned_object(object_store, object_url, vm_path) | ||
|
|
||
| async def _load_tarballs(self, artifacts: list) -> None: | ||
| """Load image tarballs, uploading those the sandbox's network policy can't download.""" | ||
| signed_urls = await self._signed_image_urls(artifacts) | ||
| await self._load_docker_images(artifacts, [url if self._can_download(url) else None for url in signed_urls]) |
There was a problem hiding this comment.
The new download routes have no unit coverage. The existing upload test calls _write_unsigned_object directly, so it cannot catch mistakes in _can_download, _download_object_to_vm, or _load_tarballs. Add tests showing that allowed signed URLs use curl, blocked or missing URLs use uploads, and mixed image lists choose the right route for each image. This would catch regressions in file and image delivery under a restricted policy.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agent_env/providers/sandbox_providers/boat/sandbox.py
Line: 209-222
Comment:
**Download routes lack tests**
The new download routes have no unit coverage. The existing upload test calls `_write_unsigned_object` directly, so it cannot catch mistakes in `_can_download`, `_download_object_to_vm`, or `_load_tarballs`. Add tests showing that allowed signed URLs use curl, blocked or missing URLs use uploads, and mixed image lists choose the right route for each image. This would catch regressions in file and image delivery under a restricted policy.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
The
boatprovider refused everynetwork_policythat restricts egress. boat now has network policies on thecreate call, so the provider maps an AgentEnv allowlist to one. This PR also adds a
snapshotconfig key (asboxdhas), fixes two rate-limit bugs, and adds the provider README.
What changed
network_policyallowlistNetworkPolicyUnsupportedError, alwaysallowpolicy, sent with the create, enforced on the sandbox's host before the sandbox is returnednetwork_policycreate_vmand onget_sandboxsupports_network_policy*.wildcards, public IPv4/IPv6 addresses or rangesboxd)snapshotconfig keycreate_vm(env=...)TypeError(argument missing)Retry-Aftertrial_compute_limit_reachedboat-sdk~=1.13.0~=1.15.0(first version withnetworkon the create)Design notes:
_wait_readyreturns only when the sandbox is readyand boat reports the policy as enforced. No command runs in an open sandbox.
invalid_network_policy,network_policy_unsupportedandapi_key_action_forbiddenon a create that carries a policy becomeNetworkPolicyUnsupportedError. boat madenothing in each case. The same codes on a create without a policy are raised unchanged.
deletes the sandbox and raises.
create_vm(image=...)stays refused. In this interface it is a VM disk image (onlylocalandmodal_vmbootone). boat boots its Ubuntu image or a saved snapshot. Docker images run through the inherited
create_container,which already works. The error message now says so.
network.writestill works for them.The key needs
network.writefor a restricted runboat's
cikey preset does not holdnetwork.write. A restricted run with such a key fails with:The README documents the key to create.
Tests
Unit (offline, in-memory SDK stand-ins, same files and style as before):
ruff check src/agent_env/providers/sandbox_providers/boat tst/unit/providers/sandbox_providers/boat_*.py pytest tst/unit/providers/sandbox_providers/boat_sandbox_provider_test.py \ tst/unit/providers/sandbox_providers/boat_sandbox_test.py \ tst/unit/providers/sandbox_providers/network_policy_stamping_test.py \ tst/unit/providers/sandbox_providers/provider_capabilities_test.py \ tst/unit/providers/sandbox_providers/egress_hosts_test.pyResult:
ruffclean; 206 passed, 1 skipped.Integration, on real boat sandboxes (
tst/integration/providers/sandbox_providers/boat_sandbox_smoke_test.py, onenew test: an allowlisted sandbox reaches an allowed host and another boat sandbox's hosted port, and nothing else,
also from the Docker daemon; a fresh provider reads the same policy back):
Result: 4 passed in 34.5 s, with a key that holds
network.write.End to end through
agent-env run ... --sandbox boat, real sandboxes:helloecho-mcp(env built from a Dockerfile, gateway, verifier)deploy_env185.9 s,env_outcome_verifier1/1), sandbox torn downexample.com+140.82.112.0/20docker pullfailsdocker pullall failnginx:alpine, port 80--keephttps://…-8080.on.boat.devand…-9090.on.boat.devanswer 200 from outsidesnapshot = "..."+ allowlist with no entrycikey + allowlistNo sandbox was left after any of these runs. A
kill -9of the CLI leaves its sandbox, as on every provider; boatstops it at the sandbox's
timeout, andGET /sandboxes?label=agentenv.managed=truefinds it.Things reviewers should know
denymode is not reachable througheffective_network_policy.policy_requeststill maps an empty list todeny, for a caller that builds one.*.example.comalso coversexample.com.allows_hostfollows boat's rule, not boxd's.200with boat's own page. It is notegress. A verifier must test HTTPS or a domain name.
/docs/sandboxes#boat) still says boat has no egress allowlist. It needs the same update asthe README in this PR.
🤖 Generated with Claude Code
Confidence Score: 4/5

Fix the terminal-refusal cleanup path before merging.
Findings
Fix with agent prompt
Summary
Adds boat allowlists, saved-snapshot startup, policy read-back, and policy-aware file transfers. Updates create retries to honor boat's requested waits.
Diagram
%%{init: {'theme': 'neutral', 'htmlLabels': false}}%% flowchart TD A[Create request] --> B[Add network policy and saved snapshot] B --> C[Create boat sandbox] C --> D[Wait for readiness and policy enforcement] D --> E[Return handle with reported policy] E --> F{Download host allowed?} F -->|Yes| G[Sandbox downloads signed URL] F -->|No| H[Host uploads file]Reviews (1) · Last reviewed commit: "feat(boat): enforce network policies, st..." · Reviewed by Greptile