Repository navigation
Add Boat backend for sandbox tools - #71725
Conversation
4e23c20 to
994acd8
Compare
344903c to
13148b9
Compare
|
Quickest fix: git fetch upstream main && git rebase upstream/main
rm uv.lock && uv lock
git add uv.lock && git rebase --continue
git push --force-with-leaseAutomated nudge — ignore if you're not ready to rebase. This comment is updated in place on future |
|
Here’s the Airflow UI view from a fresh run of this PR’s I first ran the checked-in system test unchanged ( |
2b71bac to
41570aa
Compare
cd6b138 to
195ad5e
Compare
Boat snapshots a sandbox in the background by default, which costs CPU and memory and keeps a stopped sandbox's disk. This backend never resumes or forks a sandbox, so the snapshot only kept an agent's files around after the TTL stopped it. Creating with snapshots=False means the TTL now stops the sandbox and erases its disk, and the docs that said it archives the sandbox and keeps its snapshot say that instead.
ready_timeout was spent twice: the create call's HTTP timeout got all of it, and the readiness polls then started a fresh ready_timeout of their own. One monotonic deadline is now taken before the create and shared by the create call and the polls, so provisioning as a whole ends at ready_timeout, with request_timeout of slack on a single HTTP call. The create now carries a per-create idempotency key. When its answer may have been lost to a timeout, a transport error or a 5xx, it is sent once more with the same key and body inside what is left of the deadline; Boat answers that with the sandbox the first request created, so the retry cannot bill a second one. A 409 idempotency_in_progress on the retry is retried shortly with the same key until the deadline, and any other failure of the retry is terminal. The error-body helper is typed str | None, as boat-sdk declares ApiException.body, which makes its bytes branch unreachable, so it is gone; the envelope parsing is split out so the retry can read the code.
A request between 586 and 600 seconds was shortened to 585, but one over 600 was refused with a SandboxError, so the same kind of request was handled two ways depending on which side of the API's own limit it fell. Every request above the ceiling is now shortened to it, and applied_timeout tells the model the deadline the command really had.
The backend only read BOAT_API_KEY from the worker environment, so a deployment had to put the key in every worker's environment instead of in the secrets backend it already uses for other connections. A new keyword-only boat_conn_id names a generic Airflow connection, resolved on first use as OpenSandbox's is: its password is the API key and is required, and its host, when set, is the API base URL. None keeps the environment variables, so existing Dags behave as before.
The test only checked that the parent-directory command contained "mkdir -p", which "mkdir -p -- <path>" also does, and that would turn the file's own path into a directory and break every nested write. It now runs the generated command in a local login shell, as Boat does, against a path with a space and a single quote, and checks that the parent exists and the file path itself does not.
What sets this backend apart from a destroy-on-timeout one is that the in-guest deadline stops a command while the sandbox and its files survive, and only a live sandbox can show that. As Modal's system test does, the agent now runs sleep 30 with a 2 second timeout, checks the result says it timed out and not that the sandbox was replaced, then reads back the file it wrote first and runs one more command.
The comparison listed how write_file treats a symlink on sbx, Modal and OpenSandbox but left Boat out. Measured on a live sandbox, Boat's native write API follows the link: the link stays a symlink and its target receives the content, as on sbx.
|
@zozo123 Bringing 2 things from our Slack chat:
|
The client used urllib3's default Retry(3), so a readiness GET that never answered was sent four times, each with its whole HTTP timeout, and a connect failure on the create was resent the same way. One call could then run four times the timeout it was given, and provisioning was not bounded by ready_timeout as documented. Failed requests are no longer resent by the HTTP client; the backend's own create retry is the only one. Redirects are still followed, which retries=False would stop.
The first create request was given what was left of ready_timeout plus request_timeout, so its read timeout only arrived past the deadline and the retry it was meant to trigger was skipped. A create whose answer was lost to a timeout, the case most likely to leave a billed sandbox behind, was therefore never retried. The first request now gets at most request_timeout, so a lost answer leaves time for the retry; Boat answers a retry made while it is still creating the sandbox with idempotency_in_progress, which is retried until the deadline. The one retry is sent even at the deadline, with request_timeout to spare, because only its answer names a sandbox the first request may have started, which create then deletes. The rename also shares the deadline, and the deadline starts once the client exists, so a slow connection lookup does not eat into provisioning. Tests let a read timeout arrive only after the call's own HTTP timeout, and cover the status 0 that boat-sdk uses for a TLS failure.
The timeout clamp edit left one 145-character line in a file wrapped at about 80 columns. Text is unchanged.
|
hey @kaxil, Anicet here, co-founder of Boat. We have built this infra for a year, raised $1M and are in YC, so this is a long-term commitment. For the system test, create a Boat account for this, and once signed up once send me its email. We will gift it a long-term plan, so the test is not blocked on billing. |
A connection defined in Airflow's URI form, such as generic://:[email protected]/api/v1, leaves the bare domain boat.dev in host. Used as the base URL, that made urllib3 fall back to plain HTTP on port 80 and send the API key as an unencrypted bearer token. The backend now requires the host to be an http:// or https:// URL and fails with an error naming the connection before any client is built or request sent.
The create retry treated an ApiException with status 0 as a TLS failure whose answer may have been lost. With the Retry this client is built with, urllib3 turns a TLS failure into MaxRetryError before boat-sdk's SSLError handler runs, and that already counts as a lost answer. The only status 0 left is boat-sdk failing to build the request, which was never sent and would fail the same way again, so it is now terminal.
The docs said a sandbox the create retry finds too late is deleted, which read as if a lost create could never leave one behind. When Boat is still answering idempotency_in_progress as ready_timeout runs out, the backend never learns the sandbox's id, so it keeps a server-assigned name that an airflow-sandbox-* sweep misses and runs until ttl_seconds stops it.
The client's Retry still honoured Retry-After on a 413, 429 or 503, so one call could sleep and resend past the deadline it was given. Also name the second way a lost create can leave a sandbox running, and reflow two lines.
mypy for providers checks the tests too, and urllib3 types the pool argument of ReadTimeoutError and MaxRetryError as a ConnectionPool.
|
@AnicetNgrt the account offer helps with billing, thanks. By maintenance commitment I meant who does the work on this backend inside the Airflow repo after it merges. From then on Airflow committers release it, and users file issues against So we need named people (GitHub handles, at least two, the same bar as provider stewards in the stewardship model) who will:
|
|
Status at
Drafted-by: Claude Code (Opus 5.5) (no human review before posting) |
# Conflicts: # providers/common/ai/README.rst
The docs said a lost create is retried once, but the backend keeps resending while Boat answers 409 idempotency_in_progress, until ready_timeout runs out. The Boat docs also left out that the write_file path rule is not a jail: commands run as a user with sudo on a VM with a public address and an in-guest firewall, as Boat's own docs state.
# Conflicts: # providers/common/ai/docs/sandbox/backends.rst # providers/common/ai/tests/system/common/ai/README.md
boat-sdk 1.9.3 added a monitoring flag to the create request that defaults to on, and with it on Boat keeps each command's output and process history for the sandbox. The command text includes the SandboxSpec.env exports the backend prepends. Creates now pass monitoring=False, which needs boat-sdk>=1.9.3. Also apply the base URL scheme check to BOAT_BASE_URL, not only to a connection host; assert in the system test that a background process does not hold the call open and that the one sandbox is torn down; and name ttl_seconds wherever the lifetime docs name sandbox_timeout.
Boat gives every member of an organization use of a noEnv sandbox billed to that organization: they can open it, run commands in it, and read and write its files. Without an org in the create request, Boat bills the account's active wallet, which can be an organization. Creates now pass org="personal" unless the new org parameter names one, and the docs warn what naming one means. Also refuse to create a sandbox when the installed boat-sdk is too old to send monitoring=False, which it would otherwise drop from the request.


Adds a hosted Boat backend for
SandboxToolset, giving containerized Airflow workers a production-capable backend without a local daemon or KVM.Boat is the service formerly called Ascii Box: the vendor renamed it on 2026-09-15 and published
boat-sdk1.0.0 the next day. The oldascii.dev/api/box/v1base now answers withDeprecationandSunset: 31 Oct 2026headers (see Migrating from Box to Boat), so this PR ships the backend under the new name from the start:BoatSandboxBackendand theboatextra onboat-sdk>=1.5.0.Credentials come from a generic Airflow connection when
boat_conn_idis set, the same shape asopensandbox_conn_id: the password is the API key and the host, when set, is the API base URL with its scheme. Withboat_conn_id=None(the default) the backend readsBOAT_API_KEY(required) andBOAT_BASE_URL(optional, defaulthttps://boat.dev/api/v1) from the worker environment. Nothing is read until the first sandbox is created.What changed
SandboxSpec.envat creation, refusesblock_network,allow_egress_toandallow_egress_to_cidrsbecause Boat enforces no egress policy, and refusesownerbecause Boat keeps no per-sandbox metadata an attach could be checked against;SandboxSpec.envbefore each command because the image profile would otherwise override values such asLANGandPATH;/home/useror/tmp, which the docs state), and keeps the inherited shell read and listing, which bound a read inside the guest instead of after the bytes have reached the worker;timeout, so a timed-out command returns its partial output and the sandbox is kept, as on Modal; Boat's own deadline, 15 s later, is the backstop, and only it destroys the sandbox. A request above the API's cap is clamped and reported throughapplied_timeout;noEnv=True(none of the account's secrets) andsnapshots=False, so the server-side TTL stops an orphaned sandbox and erases its disk;ready_timeoutdeadline and sends each create with an idempotency key: a create whose answer may have been lost (timeout, transport error or 5xx) is resent with the same key, and resent again 2 s after each 409idempotency_in_progressanswer untilready_timeoutruns out, and Boat answers a repeated key with the first request's sandbox rather than creating a second;delete_sandbox(a 404 counts as already deleted), andrequest_timeoutbounds every API call, with urllib3's own resends turned off;boat-sdklazily and exports the backend eagerly (the module imports the SDK on first use, so the package stays importable without it and a missing SDK surfaces as an actionable error);boatextra, that the/home/useror/tmprule binds onlywrite_file, and, from Boat's machine and hosting docs, that commands cansudoto root on a VM with a public address and an in-guest firewall; adds unit plus system coverage; and_validate_positive_finiteinsandbox/base.pynow rejects booleans (sottl_seconds=Truecannot pass as 1), and thesbxdocstring lists Boat as a managed alternative.Validation
test_boat.py(also under Python 3.11), covering both credential paths, the refusals, the in-guest deadline and the clamp, the idempotent create resends, readiness polling, file ops and the idempotent delete;https://boat.dev/api/v1on 2026-10-07 at0288dc04cd(1 passed in 16.52s);boat_conn_idconnection with noBOAT_API_KEYin the environment created, ran and deleted a sandbox; a create withsnapshots=Falsesucceeded and Boat reported no snapshot; a second create with the same idempotency key returned the same sandbox; a write through the native file API to a symlink kept the link and wrote its target;echo partial; sleep 60with a 5 s budget came back after 5.3 s withpartialin stdout and the sandbox still usable;0288dc04cd; since thenboat.pychanged only in docstrings andexample_sandbox_toolset_boat.pynot at all (git diff 0288dc04cd..HEAD), the rest being tests, docs and merges ofmain.Related: #68847
See also: #71672, #71676
Was generative AI tooling used to co-author this PR?
Generated-by: Cursor (Grok), Claude Code (Opus 5), Claude Code (Fable 5.1), Claude Code (Opus 5.5), Codex (GPT-6) following the guidelines