airflow.providers.common.ai.sandbox.base¶
Vendor-neutral contract for running agent commands and file operations in an isolated sandbox.
Exceptions¶
A sandbox operation failed in a way the agent may be able to work around. |
|
The sandbox is unusable and retrying the same call cannot succeed. |
|
A file is larger than the caller's read budget, so it was not transferred. |
Classes¶
What a single sandbox should be provisioned with. |
|
Outcome of one command executed inside a sandbox. |
|
Contract for running commands and file operations in an isolated sandbox. |
Module Contents¶
- exception airflow.providers.common.ai.sandbox.base.SandboxError[source]¶
Bases:
ExceptionA sandbox operation failed in a way the agent may be able to work around.
The toolset turns this into a
ModelRetryso the model can adjust and try again within the run (a bad path, a command the image cannot run).
- exception airflow.providers.common.ai.sandbox.base.SandboxTerminalError[source]¶
Bases:
SandboxErrorThe sandbox is unusable and retrying the same call cannot succeed.
Credentials were rejected, the daemon is unreachable, the sandbox is gone. The toolset lets this propagate and fail the task, so Airflow’s own retry handles it rather than the model burning its retry budget.
- exception airflow.providers.common.ai.sandbox.base.SandboxFileTooLargeError(path, size_bytes, max_bytes)[source]¶
Bases:
SandboxErrorA file is larger than the caller’s read budget, so it was not transferred.
- class airflow.providers.common.ai.sandbox.base.SandboxSpec[source]¶
What a single sandbox should be provisioned with.
Passed to
SandboxBackend.create(). Every field is optional and a backend may not be able to honor all of them; a backend that cannot enforce a field it was given must raise rather than silently ignore it, so a DAG author never believes a restriction is in force when it is not.- Parameters:
env – Environment variables to set inside the sandbox. Airflow never populates this itself – the DAG author decides what, if anything, the sandbox is given. Anything placed here is visible to model-generated code, so scope it to what that code legitimately needs.
block_network – Deny all outbound network access. Defaults to
True: an isolated sandbox that cannot phone home is the safe starting point, and egress is opened deliberately.allow_egress_to – Hostnames the sandbox may reach when
block_networkisTrue. An empty or unset value withblock_network=Truemeans no egress at all.
- allow_egress_to: collections.abc.Sequence[str] | None = None[source]¶
- class airflow.providers.common.ai.sandbox.base.SandboxExecResult[source]¶
Outcome of one command executed inside a sandbox.
timed_outmeans the command hit the budget, soexit_codecarries no meaning.stdout_truncated/stderr_truncatedmean the backend dropped bytes while reading that stream, before any model-facing formatting.sandbox_terminatedmeans the backend destroyed the sandbox to stop the command, so the toolset must provision a fresh one before the next call.
- class airflow.providers.common.ai.sandbox.base.SandboxBackend[source]¶
Bases:
abc.ABCContract for running commands and file operations in an isolated sandbox.
The lifecycle is create -> (any number of operations) -> destroy, driven by
SandboxToolset. The four operation methods are named after the four tools the toolset exposes, so the mapping from a model-facing tool to the backend call behind it is literal;createanddestroyare lifecycle and have no tool.Implementations must be cheap to construct, because constructors run at Dag-parse time: resolve credentials and open connections lazily, on first use.
destroymust be idempotent – destroying an already-gone sandbox is not an error. All methods are synchronous; the toolset offloads them to a thread, so a call may block for as long as its timeout allows.Raise
SandboxErrorfor a failure the model could work around, andSandboxTerminalErrorfor one it cannot.- abstract create(*, spec=None)[source]¶
Provision one sandbox and return its handle (name or id).
specofNonemeans “no requirements stated”: the backend applies its own defaults and makes no guarantee. It is not the same as a defaultSandboxSpec, which is an explicit request for an isolated sandbox. The toolset always sends a concrete spec, soNoneonly reaches a backend a caller drives directly.Raise
SandboxTerminalErrorifspecasks for something this backend cannot enforce, rather than provisioning something weaker than was asked for. It is terminal rather than recoverable because it states a configuration fact the model cannot see and cannot fix by retrying.
- abstract run_command(sandbox, command, *, timeout, max_output_bytes)[source]¶
Run
commandthrough a shell in the sandbox, bounded bytimeoutseconds.max_output_bytesbounds what the backend retains per stream while reading, so unbounded command output cannot exhaust worker memory before the toolset gets a chance to format it.
- read_file(sandbox, path, *, max_bytes)[source]¶
Read a file from the sandbox.
Raise
SandboxFileTooLargeErrorinstead of transferring a file larger thanmax_bytes.