Skip to content

feat(boat): enforce network policies, start from saved snapshots, honor boat's retry waits - #1012

Open
AnicetNgrt wants to merge 1 commit into
scaleapi:mainfrom
ariana-dot-dev:boat-network-policy
Open

AnicetNgrt wants to merge 1 commit into
scaleapi:mainfrom
ariana-dot-dev:boat-network-policy

Conversation

@AnicetNgrt

@AnicetNgrt AnicetNgrt commented Dec 6, 2026 •

Copy link
Copy Markdown

Summary

The boat provider refused every network_policy that restricts egress. boat now has network policies on the
create call, so the provider maps an AgentEnv allowlist to one. This PR also adds a snapshot config key (as boxd
has), fixes two rate-limit bugs, and adds the provider README.

What changed

Area Before After
network_policy allowlist NetworkPolicyUnsupportedError, always boat allow policy, sent with the create, enforced on the sandbox's host before the sandbox is returned
Handle's network_policy always allow-all the policy boat reports, on create_vm and on get_sandbox
supports_network_policy false for any restriction true for at most 100 domains, *. wildcards, public IPv4/IPv6 addresses or ranges
Object and tarball downloads sandbox always fetched the signed URL sandbox fetches only when the policy admits the host; else the host uploads (same pattern as boxd)
snapshot config key none every sandbox starts from that boat saved snapshot
create_vm(env=...) TypeError (argument missing) accepted, as on the other VM providers
Create refused with Retry-After waited at most 30 s, then retried early and spent attempts waits what boat says, up to 120 s; a longer wait is raised at once
trial_compute_limit_reached retried 6 times raised at once (no wait clears it)
boat-sdk ~=1.13.0 ~=1.15.0 (first version with network on the create)

Design notes:

  • One call, no window. The policy goes in the create request. _wait_ready returns only when the sandbox is ready
    and boat reports the policy as enforced. No command runs in an open sandbox.
  • Refusals move a fallback chain on. boat's invalid_network_policy, network_policy_unsupported and
    api_key_action_forbidden on a create that carries a policy become NetworkPolicyUnsupportedError. boat made
    nothing in each case. The same codes on a create without a policy are raised unchanged.
  • Fail closed. If boat reports an unrestricted policy for a sandbox that was asked a restricted one, the provider
    deletes the sandbox and raises.
  • create_vm(image=...) stays refused. In this interface it is a VM disk image (only local and modal_vm boot
    one). 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.
  • Unrestricted runs send no policy, so a key without network.write still works for them.

The key needs network.write for a restricted run

boat's ci key preset does not hold network.write. A restricted run with such a key fails with:

NetworkPolicyUnsupportedError: boat refused the network policy {...}: This API key cannot change a network policy: that needs network.write.

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.py

Result: ruff clean; 206 passed, 1 skipped.

Integration, on real boat sandboxes (tst/integration/providers/sandbox_providers/boat_sandbox_smoke_test.py, one
new 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:

Run Result
hello passed, 15.8 s, sandbox torn down
echo-mcp (env built from a Dockerfile, gateway, verifier) passed in 188.2 s (deploy_env 185.9 s, env_outcome_verifier 1/1), sandbox torn down
Allowlist example.com + 140.82.112.0/20 passed 5/5: allowed domain answers; allowed range answers on TCP 22; other domain fails over HTTPS, by name and by address; other domain does not resolve; docker pull fails
Allowlist with no entry passed 6/6: HTTPS, HTTP by name, DNS, ping, TCP 22 and docker pull all fail
Container mode, nginx:alpine, port 80 passed
Two exposed ports, --keep passed; both https://…-8080.on.boat.dev and …-9090.on.boat.dev answer 200 from outside
Ctrl-C on the kept run "Tore down 1 sandbox.", none left
Ctrl-C while boat creates the sandbox exit 130, "cancelled in 2.7s"; the sandbox that create made is deleted, none left
snapshot = "..." + allowlist with no entry passed: sandbox has the snapshot's file and runs its Docker image with no registry access
ci key + allowlist fails before any sandbox exists, with the error above; the unrestricted task in the same run passed

No sandbox was left after any of these runs. A kill -9 of the CLI leaves its sandbox, as on every provider; boat
stops it at the sandbox's timeout, and GET /sandboxes?label=agentenv.managed=true finds it.

Things reviewers should know

  • AgentEnv adds every platform's hosts to each allowlist, so boat deny mode is not reachable through
    effective_network_policy. policy_request still maps an empty list to deny, for a caller that builds one.
  • boat's wildcard *.example.com also covers example.com. allows_host follows boat's rule, not boxd's.
  • Under a boat policy, plain HTTP to an IP address that is not allowed answers 200 with boat's own page. It is not
    egress. A verifier must test HTTPS or a domain name.
  • The website page (/docs/sandboxes#boat) still says boat has no egress allowlist. It needs the same update as
    the README in this PR.

🤖 Generated with Claude Code

Confidence Score: 4/5RetriggerView in Greptile

Fix the terminal-refusal cleanup path before merging.

FindingsFix All in Cursor

  1. P1 Failed creates leave sandboxes running ▶
  2. P2 Download routes lack tests ▶
Fix with agent prompt
### Issue 1
src/agent_env/providers/sandbox_providers/boat/lifecycle.py:188-191
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.

### Issue 2
src/agent_env/providers/sandbox_providers/boat/sandbox.py:209-222
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.

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!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds boat allowlists, saved-snapshot startup, policy read-back, and policy-aware file transfers. Updates create retries to honor boat's requested waits.

  • Boat sandboxes enforce allowlists before they are returned.
  • Boat sandboxes use uploads when allowlists block file downloads.
  • Boat sandboxes can start from a configured saved snapshot.
  • Boat create retries wait as long as boat asks, within the provider’s limit.
  • Boat’s VM creator accepts the shared optional environment argument.

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]
Loading

Reviews (1) · Last reviewed commit: "feat(boat): enforce network policies, st..." · Reviewed by Greptile

…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>
@AnicetNgrt
AnicetNgrt requested a review from a team as a code owner December 6, 2026 20:11
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedpypi/​boat-sdk@​1.13.0 ⏵ 1.15.0100100100100100

View full report

Comment on lines +188 to 191
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Fix in Cursor Fix in Claude Code Fix in Codex

Comment on lines +209 to +222
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])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

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!

Fix in Cursor Fix in Claude Code Fix in Codex

This branch has not been deployed

No deployments
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.

1 participant