Install the modal package and authenticate with modal setup or by setting the MODAL_TOKEN_ID and MODAL_TOKEN_SECRET environment variables.
Define a Modal App and an Image with the required packages: app = modal.App(); image = modal.Image.debian_slim().pip_install('torch', ...).
Decorate your function with @app.function(gpu='A10G', image=image, timeout=300) to request a GPU instance and specify runtime dependencies.
Inside the function body, write standard Python code; Modal handles containerization, scheduling, and GPU attachment automatically.
Deploy the app with modal deploy script.py for a persistent deployment, or run it ephemerally with modal run script.py during development.
Call the deployed function from any Python environment using the Modal client with the .remote() method on the function handle.
Known gotchas
Cold starts on GPU functions can take tens of seconds; if model weights are loaded inside the function body, consider using @app.cls with a @modal.enter() method to load weights once per container lifecycle.
The image definition is hashed and cached; adding a pip_install call invalidates the cache and triggers a full image rebuild—group package installs to minimize rebuilds.
Modal functions execute in isolated containers and cannot access the local filesystem; use modal.Volume or modal.CloudBucketMount to persist or share data between runs.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp