Modal.Environment reference
Environment
Section titled “Environment”Source:
packages/modal/src/Environment.ts
A Modal Environment: an isolated namespace inside a workspace for Apps, Volumes, Dicts, Queues, Secrets and Sandboxes, with its own concurrency limits, spend budget and member roles. Objects with the same name in two environments are different objects, so one environment per stage keeps stages apart.
Modal environments have no tags. Ownership is inferred from Alchemy
state: an environment found under an explicit name without prior state
is reported as unowned.
Environment: Creating an Environment
Section titled “Environment: Creating an Environment”One environment per stage
import * as Modal from "@alchemy.run/modal";
export const Agents = Modal.Environment("Agents", {});Limits and a monthly budget
import * as Modal from "@alchemy.run/modal";
export const Agents = Modal.Environment("Agents", { maxConcurrentTasks: 50, maxConcurrentGpus: 4, budget: 200,});Environment: Access control
Section titled “Environment: Access control”import * as Modal from "@alchemy.run/modal";
export const Production = Modal.Environment("Production", { name: "production", managed: true, defaultMemberRole: "viewer", roles: [{ userId: "us-1234", role: "contributor" }], blockUnauthenticatedResources: true,});Environment: Using the environment
Section titled “Environment: Using the environment”import * as Modal from "@alchemy.run/modal";
export const Agents = Modal.Environment("Agents", {});export const Coder = Modal.App("Coder", { environment: Agents });export const Workspace = Modal.Volume("Workspace", { environment: Agents });Environment: Looking up an existing environment
Section titled “Environment: Looking up an existing environment”Environment.lookup references an environment Alchemy doesn’t manage (created with
the Modal CLI or by another stack). It is read during plan/deploy, never
created, updated or deleted.
const staging = Modal.Environment.lookup({ name: "staging" });