Repository navigation
Let the Modal sandbox backend read credentials from a modal connection - #74302
Merged
Merged
Conversation
ModalSandboxBackend could only use ambient Modal credentials (MODAL_TOKEN_ID / MODAL_TOKEN_SECRET or ~/.modal.toml), so a deployment that keeps secrets in a secrets backend could not use the sandbox toolset on Modal without putting a token in the worker environment. It now takes modal_conn_id (default modal_default) and builds its Modal client through the Modal provider's ModalHook, which falls back to the ambient credentials when the default connection does not exist. The modal extra now installs apache-airflow-providers-modal, which needs Airflow 3, so the Modal backend is gated on Airflow 3 the way the skills and git extras already are.
Build the Modal client in one place, under a lock, so concurrent first calls on a shared backend cannot each open a client, and translate credential errors there instead of at every call site. Point the docs at the Modal connection page for the credential precedence rather than restating it, and drop tests that re-checked ModalHook rules the Modal provider already tests.
vatsrahul1001
approved these changes
Oct 6, 2026
eladkal
approved these changes
Oct 6, 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.
ModalSandboxBackendcould only authenticate with ambient Modal credentials (MODAL_TOKEN_ID/MODAL_TOKEN_SECRETin the worker environment, or~/.modal.toml). A deployment that keeps secrets in a secrets backend, or wants a different Modal workspace per Dag, had to put a token in the worker environment to use the sandbox toolset on Modal.The backend now takes
modal_conn_id(defaultmodal_default) and builds its Modal client through the Modal provider'sModalHook(#73418), whose docstring already names this backend as a caller:The connection's token and optional
environmentare used for creating, reattaching to and destroying sandboxes. Without amodal_defaultconnection the hook falls back to the ambient credentials, so an Airflow 3 deployment that relies on them today keeps working with no configuration.Design rationale
The Modal backend now needs Airflow 3. The
modalextra addsapache-airflow-providers-modal, which requires Airflow 3.0, while Common AI supports 2.11. This follows the precedent of theskillsandgitextras, andinstallation.rstnow listsmodalbeside them. Making the provider optional would have kept the backend on Airflow 2.11, but the connection is what this backend offers over pydantic-ai's ownModalSandboxcapability, so a Modal backend without it has little reason to exist. Common AI's Airflow 2 support is unreleased (0.10.0 floors Airflow 3), so no released user loses anything.Credential problems fail the task, never the model. A named connection that does not exist, or one with only half of the token, raises
SandboxTerminalErrornaming the connection. Nothing the model does can fix it.destroyraises too, so a cleanup task with a misspelled connection fails instead of leaving the sandbox billing until its lifetime ends; the toolset's own teardown already catches and logs this, so a finished agent run is never failed by teardown. When Modal rejects a token that came from the connection, the error says to update the connection rather than to set worker environment variables, which would change nothing.Nothing is read at Dag-parse time. The hook is constructed in
__init__, which reads no connection and opens no client; both wait for the first sandbox.Verified live against Modal: with no
MODAL_TOKEN_*in the environment and no~/.modal.toml, a backend withmodal_conn_idcreated a sandbox, ran a command, and a second backend instance reached the same sandbox by handle and destroyed it. The default path in the same environment failed with Modal's "Token missing", confirming the run used only the connection. That run was on the revision before review fixes, which moved the hook's construction into__init__and changed error reporting but not the credential path; the unit suite covers both.Gotchas
apache-airflow-providers-modalis unreleased (0.1.0), so the Common AI release carrying this needs to ship in the same wave as the Modal provider or after it.modalextra gets an optional-feature error importingModalSandboxBackenduntil the Modal provider is installed.ModalHooktreats a missingmodal_defaultas permission to use ambient credentials, and the Task SDK reports a secrets-backend outage as the same not-found error. Withmodal_defaultin a secrets backend and Modal credentials also on the worker, an outage would provision in the worker's Modal account. That is the hook's behavior for every caller, so it is left for a follow-up in the Modal provider rather than special-cased here.{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.