Repository navigation
Export files an agent built in a sandbox to object storage - #73990
Merged
Merged
Conversation
…rdown
SandboxToolset(exports={sandbox_path: storage_url}) copies each file out
when the run ends and before the sandbox is destroyed, streaming through the
worker without passing the model's context or XCom. A promised file that
cannot be exported fails the task; a failed run exports nothing; a teardown
failure after a good export only logs.
Backends gain SandboxBackend.export_file, a concrete default that reads the
file in bounded slices through run_command, overridden to stream natively on
sbx and OpenSandbox.
Lee-W
reviewed
Oct 1, 2026
Each file is now copied to a sibling staging key and moved into place only after every file has been copied, so a failed export no longer deletes or truncates what was already at a destination. Exports are also bounded by a total deadline that scales with max_export_bytes, so a guest trickling bytes cannot hold the task open past the stall timeout. Co-Authored-By: Claude <[email protected]>
vatsrahul1001
approved these changes
Oct 1, 2026
This was referenced Oct 8, 2026
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.
A file an agent builds in a
SandboxToolsetsandbox is destroyed with the sandbox when the run ends. The only way anything leaves today is through the model's context, which is text-only and capped at 50 KiB per command stream and 5 MiB perread_file. So "the agent produces an artifact" (a parquet file, a chart, a cleaned CSV, a trained model) has had no path out, short of the attach shape where a separate task provisions the sandbox and reads the file afterwards.This adds
exports: name the files the agent will write and where each should land, and the toolset copies them to object storage when the run ends, before it destroys the sandbox.Destinations are templated when the toolset goes through
AgentOperator, the same wayattach_tois, and anythingObjectStoragePathcan open works. Therun_commandtool description tells the model which files will be collected, so it writes them where they are expected.Design rationale
Why not raise
max_read_bytesinstead. Reading a file through the model's tools costs roughly three times its size in worker memory, and the point is to move the file, not to show it to the model. The copy here never goes through the model or XCom.A new backend method, with a default so no backend has to change.
SandboxBackend.export_file(sandbox, path, dest, *, max_bytes)writes into a binary stream without holding the file. The default on the base class reads 4 MiB slices throughrun_command, so a third-party backend gets exports for free.sbxoverrides it to stream a singleexecstraight into the destination, and OpenSandbox uses the SDK's ranged download. Only regular files are exported, and a file whose size changes during the copy is an error, since something in the sandbox is still writing it.What fails the task and what does not. A promised file that cannot be exported (missing, a directory, over
max_export_bytes, changed mid-copy, or refused by storage) fails the task and leaves every destination as it was. Each file is copied to a.partialstaging key beside its destination, and the files are moved into place only once all of them have been copied (a rename on local disk, a server-side copy on object storage). The whole copy is also bounded by a deadline ofmax_export_bytesat 1 MiB/s, so a guest trickling bytes cannot hold the task open. The sandbox is destroyed either way. Adestroythat fails after a good export only logs the sandbox name, as teardown failures already do. A run that failed exports nothing.Detecting a failed run. pydantic-ai exits its toolsets through an exit stack that passes
Noneto__aexit__whether or not the run raised, so the toolset reads the exception being handled at exit instead. An exception that was already being handled when the run entered is ignored, so an agent started from inside anexceptblock still exports.Refused together with
attach_to. An attached sandbox belongs to the task that created it, which already reads out whatever the agent left, and that shape is also the one to use when files must survive a failed run.Evidence
On a local
sbxmicroVM, exporting a 200 MB random file took about 2.6 s, and the sha256 on the worker matched the one computed in the guest. Worker peak RSS was 259 MB for a 20 MB export and 260 MB for a 400 MB one, so the copy is bounded by chunk size rather than file size.Gotchas
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.