Repository navigation
feat(sandbox): configure the Modal environment for modal and modal_vm - #175
Merged
Merged
Conversation
Both Modal providers take an optional `environment_name` from their `[sandbox.providers.<name>.config]` table. It goes to `modal.App.lookup`, so the Apps, and the sandboxes and image builds in them, land in that environment. For `modal` it also goes to `modal.Secret.from_name` for the ECR pull secret, which Modal scopes to an environment too. The process-wide cache of images built from a build context is now keyed by environment as well, so a build in one environment is not reused from another. Unset keeps today's behavior: Modal's own default, `MODAL_ENVIRONMENT`, else the workspace default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What and why
The
modalandmodal_vmproviders always create their Apps in the default Modal environment of the token's workspace: neither passesenvironment_name, so the only way to move them is a process-wideMODAL_ENVIRONMENT. A deployment that wants its sandboxes in a dedicated environment, without moving everything else that process does on Modal, has no setting for it.Both providers now take an optional
environment_namefrom their config table:modal.App.lookup. A sandbox's environment comes from its App (Sandbox.create(environment_name=)is deprecated for that reason), so sandboxes and image builds follow.modal, it also goes tomodal.Secret.from_namefor the ECR pull secret, which Modal scopes to an environment too. Without this the App and its pull secret would resolve in different environments.modal_image_build._built_image_ids) is now keyed by environment as well, so an image built in one environment isn't reused by a provider pointed at another.Unset is unchanged: Modal's own default,
MODAL_ENVIRONMENT, else the workspace default.The website's Modal section (
content/docs/sandboxes.mdx) needs a line for the new key; that's a separate PR inagent-env-website.How it was tested
pytest tst/unit/providers/sandbox_providers: 738 passed, 3 skipped. New tests:test_modal_builtins_accept_an_environment_name[modal|modal_vm]: the config table reaches both providers.test_apps_are_looked_up_in_the_configured_environment(both providers):App.lookupgets the environment.Secret.from_name(..., environment_name=...).test_each_modal_environment_builds_its_own_image_of_the_same_sources: same sources, two environments, two builds; repeats within one environment still reuse.tst/unit+packages/agentenv-protocol/tests: 17 failures intest_optional_extras_stay_optional.pyand the protocol tool-client tests. The identical 17 fail on unmodifiedmainin the same venv (it has boto3 installed and the protocol package isn't installed from the checkout), so they're environmental.ruff checkon the changed files: no new findings againstmain.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.Summary
Adds optional
environment_nameconfiguration tomodalandmodal_vm.No actionable issues found. Tests were inspected, not run; live Modal behavior was not verified.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD Config["Provider config: environment_name"] --> Provider["modal or modal_vm provider"] Provider --> App["App.lookup with environment_name"] App --> Sandbox["Sandbox creation with app"] Provider --> Secret["modal: ECR secret lookup with environment_name"] Secret --> Sandbox Provider --> Cache["modal: image cache and lock key includes environment"] App --> Build["Build context image with app"] Cache --> Build Build --> SandboxReviews (1) · Last reviewed commit: "refactor(sandbox): drop the environment_..." · Reviewed by Greptile