Skip to main content
Apps are containers for Modal resources like Functions, Classes, and Sandboxes. Use the Apps API to reference deployed apps.

Access the Apps API

import { ModalClient } from "modal";

const modal = new ModalClient();
const app = await modal.apps.fromName("my-app");

Methods

Reference a deployed App by name, or create it if it does not exist.
name
string
required
Name of the App to reference.
params
AppFromNameParams
Optional parameters
return
Promise<App>
The referenced App object.
// Reference an existing app
const app = await modal.apps.fromName("my-app");

// Create if missing
const app = await modal.apps.fromName("my-app", {
  createIfMissing: true,
});

// Use a specific environment
const app = await modal.apps.fromName("my-app", {
  environment: "staging",
});
Throws NotFoundError if the app doesn’t exist and createIfMissing is false.

App object

The App object represents a deployed Modal application.

Properties

appId
string
Unique identifier for the App.
name
string | undefined
Name of the App, if it was looked up by name.

Example: Create a sandbox in an app

import { ModalClient } from "modal";

const modal = new ModalClient();

const app = await modal.apps.fromName("my-app", {
  createIfMissing: true,
});

const image = modal.images.fromRegistry("alpine:3.21");

const sandbox = await modal.sandboxes.create(app, image, {
  command: ["echo", "Hello from sandbox!"],
});

const output = await sandbox.stdout.readText();
console.log(output);

await sandbox.terminate();

Build docs developers (and LLMs) love