Skip to content

Add Boat backend for sandbox tools - #71725

Merged
kaxil merged 72 commits into
apache:mainfrom
zozo123:add-ascii-box-sandbox-backend
Oct 14, 2026
Merged

kaxil merged 72 commits into
apache:mainfrom
zozo123:add-ascii-box-sandbox-backend

Conversation

@zozo123

@zozo123 zozo123 commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

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-sdk 1.0.0 the next day. The old ascii.dev/api/box/v1 base now answers with Deprecation and Sunset: 31 Oct 2026 headers (see Migrating from Box to Boat), so this PR ships the backend under the new name from the start: BoatSandboxBackend and the boat extra on boat-sdk>=1.5.0.

Credentials come from a generic Airflow connection when boat_conn_id is set, the same shape as opensandbox_conn_id: the password is the API key and the host, when set, is the API base URL with its scheme. With boat_conn_id=None (the default) the backend reads BOAT_API_KEY (required) and BOAT_BASE_URL (optional, default https://boat.dev/api/v1) from the worker environment. Nothing is read until the first sandbox is created.

What changed

  • maps SandboxSpec.env at creation, refuses block_network, allow_egress_to and allow_egress_to_cidrs because Boat enforces no egress policy, and refuses owner because Boat keeps no per-sandbox metadata an attach could be checked against;
  • runs each command in a login shell with stdout and stderr spooled to files and waits only for that shell, so a backgrounded process does not hold the call open, and re-exports SandboxSpec.env before each command because the image profile would otherwise override values such as LANG and PATH;
  • uses the native file write API (paths under /home/user or /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;
  • enforces the command deadline inside the guest with GNU 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 through applied_timeout;
  • creates every sandbox with noEnv=True (none of the account's secrets) and snapshots=False, so the server-side TTL stops an orphaned sandbox and erases its disk;
  • bounds provisioning by one ready_timeout deadline 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 409 idempotency_in_progress answer until ready_timeout runs out, and Boat answers a repeated key with the first request's sandbox rather than creating a second;
  • deletes through the SDK's delete_sandbox (a 404 counts as already deleted), and request_timeout bounds every API call, with urllib3's own resends turned off;
  • resolves the optional boat-sdk lazily 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);
  • documents the boat extra, that the /home/user or /tmp rule binds only write_file, and, from Boat's machine and hosting docs, that commands can sudo to root on a VM with a public address and an in-guest firewall; adds unit plus system coverage; and
  • outside the backend, _validate_positive_finite in sandbox/base.py now rejects booleans (so ttl_seconds=True cannot pass as 1), and the sbx docstring lists Boat as a managed alternative.

Validation

  • 126 unit tests pass in 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;
  • the system test, which now includes the in-guest timeout, passed end to end against https://boat.dev/api/v1 on 2026-10-07 at 0288dc04cd (1 passed in 16.52s);
  • live probes on the same code: a boat_conn_id connection with no BOAT_API_KEY in the environment created, ran and deleted a sandbox; a create with snapshots=False succeeded 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 60 with a 5 s budget came back after 5.3 s with partial in stdout and the sandbox still usable;
  • the live runs above were at 0288dc04cd; since then boat.py changed only in docstrings and example_sandbox_toolset_boat.py not at all (git diff 0288dc04cd..HEAD), the rest being tests, docs and merges of main.

Related: #68847
See also: #71672, #71676


Was generative AI tooling used to co-author this PR?
  • Yes — Cursor (Grok), Claude Code (Opus 5), Claude Code (Fable 5.1), Claude Code (Opus 5.5), Codex (GPT-6)

Generated-by: Cursor (Grok), Claude Code (Opus 5), Claude Code (Fable 5.1), Claude Code (Opus 5.5), Codex (GPT-6) following the guidelines

@zozo123

zozo123 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Airflow + Ascii Box CLI e2e proof

Committed to this PR as ascii_box_actual_cli_proof.gif. This is the actual CLI transcript from the successful real-box Airflow run: create, write, read, command output, listing, non-zero exit handling, destroy, and system test 1 passed.

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

uv.lock on main just moved via #74429 ("Prepare providers release 2026-10-06"), commit 57ad5d3 and this PR currently conflicts.

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-lease

Automated nudge — ignore if you're not ready to rebase. This comment is updated in place on future uv.lock bumps.

@zozo123

zozo123 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Here’s the Airflow UI view from a fresh run of this PR’s common_ai_sandbox_toolset_ascii_box system-test DAG.

I first ran the checked-in system test unchanged (1 passed). For the recording, I reran the same assertions with non-secret progress markers so every sandbox-boundary step is visible in the task log: write_file, successful run_command output validating file persistence + environment propagation + arithmetic, read_file, the expected exit-code-3/stderr failure path, list_directory, and teardown. The UI-triggered DAG and task both finished Success.

Airflow Ascii Box sandbox E2E

@zozo123
zozo123 force-pushed the add-ascii-box-sandbox-backend branch from 2b71bac to 41570aa Compare September 19, 2026 17:26
@zozo123 zozo123 changed the title Add Ascii Box backend for sandbox tools Add Boat backend for sandbox tools Sep 19, 2026
@zozo123
zozo123 force-pushed the add-ascii-box-sandbox-backend branch from cd6b138 to 195ad5e Compare September 22, 2026 07:57
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.
@kaxil

kaxil commented Oct 7, 2026

Copy link
Copy Markdown
Member

@zozo123 Bringing 2 things from our Slack chat:

  1. The maintenance commitment has to be public. You mentioned the Boat founders have committed to maintaining this backend. That needs to be on record where the community can see it, either here on the PR or on the dev list, not in a DM. Every backend we add is a dependency we have to keep working and keep testing. The Islo PR already shows what happens when test access lapses: the system test in Add Islo backend for sandbox tools #71672 couldn't be run end to end after the account hit 402 BILLING_NOT_ALLOWED.
  2. I'm rethinking how sandboxing fits into common.ai more broadly. A lot of users are already deep in agent frameworks like AWS Strands and Google ADK, so I'm not convinced that a growing list of backends inside common.ai is the right shape. Where a sandbox comes from a vendor that already has a provider (AWS, Google, Azure), the backend should live in that provider, with an optional dependency on common.ai. I am planning to move the Modal one to its provider too

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.
@AnicetNgrt

Copy link
Copy Markdown

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.
@kaxil

kaxil commented Oct 7, 2026

Copy link
Copy Markdown
Member

@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 apache-airflow-providers-common-ai. If your API changes underneath it, our users' DAGs break and our maintainers get the bug report.

So we need named people (GitHub handles, at least two, the same bar as provider stewards in the stewardship model) who will:

  1. Keep the backend in step with your API and boat-sdk. This PR already has an example: the old ascii.dev/api/box/v1 base sunsets on 31 Oct 2026, and the PR for a change like that should come from your team before the date.
  2. Triage and fix issues, and review PRs that touch the Boat backend, within a reasonable time.
  3. Run the system test regularly against main and publish the results, like other vendors do on the system test dashboards. The gifted account avoids the billing failure we hit on Add Islo backend for sandbox tools #71672; someone on your side still needs to run the test and act when it goes red.
  4. Accept that if this lapses, the backend gets deprecated and removed under the suspension and removal policy.

@zozo123

zozo123 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Status at 334df902c7, with main merged:

  • CI is green and every review thread is answered and resolved.
  • The 12 points from the last review are in:
    • The guest returns only the tail of each spooled stream.
    • Sandboxes are created with snapshots=False and noEnv=True, and the no_env parameter is gone.
    • Provisioning runs on one ready_timeout deadline, with one idempotency-keyed retry of a lost create.
    • Every over-cap timeout is clamped and reported through applied_timeout.
    • Credentials can come from a generic connection (boat_conn_id, the OpenSandbox shape).
    • The HTTP client no longer resends a request or sleeps out a Retry-After answer.
  • Live against boat.dev on the final backend code (0288dc04cd; later commits change only tests and merge main):
    • The system test, now with the in-guest timeout step, passed (1 passed in 16.52s).
    • A run with only a boat_conn_id connection and no BOAT_API_KEY created, used and deleted a sandbox.
  • On maintenance: the steward names requested above need to come from the Boat team.

Drafted-by: Claude Code (Opus 5.5) (no human review before posting)

zozo123 and others added 6 commits October 8, 2026 03:04
# 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.
@kaxil
kaxil merged commit c5c2f19 into apache:main Oct 14, 2026
275 of 276 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants