Modal JavaScript SDK
The Modal JavaScript SDK provides convenient, on-demand access to serverless cloud compute on Modal from JS/TS projects. Use it to safely run arbitrary code in Modal Sandboxes, call Modal Functions, and interact with Modal resources.
It comes with built-in TypeScript type definitions.
We're approaching feature parity with the main Modal Python SDK, although defining Modal Functions will likely remain exclusive to Python.
Installation
Install this in any server-side Node.js / Deno / Bun project.
npm install modal
npm package: https://www.npmjs.com/package/modal
Requirements
Node 22 or later. We bundle both ES Modules and CommonJS formats, so you can load the package with either import or require() in any project.
Documentation
See the main Modal documentation and user guides for high-level overviews. For details, see the API reference documentation for for JS.
We also provide a number of examples:
- Call a deployed Function
- Spawn a deployed Function
- Call a deployed Cls
- Call a deployed Cls, and override its options
- Create a Sandbox
- Create a named Sandbox
- Create a Sandbox with GPU
- Create a Sandbox using a private image from AWS ECR
- Take a snapshot of the filesystem of a Sandbox
- Execute Sandbox commands
- Running a coding agent in a Sandbox
- Check the status and exit code of a Sandbox
- Access Sandbox filesystem
- Expose ports on a Sandbox using Tunnels
- Include Secrets in Sandbox
- Mount a Volume to a Sandbox, and same but with an ephemeral Volume
- Mount a cloud bucket to a Sandbox
- Eagerly build an Image for a Sandbox
- Building custom Images
Authenticating with Modal
You also need to authenticate with Modal (see Getting started). Either sign in with the Modal CLI using pip install modal && modal setup, or in machine environments set these environment variables:
# Replace these with your actual token!
export MODAL_TOKEN_ID=ak-NOTAREALTOKENSTRINGXYZ
export MODAL_TOKEN_SECRET=as-FAKESECRETSTRINGABCDEF
Support
For usage questions and other support, please reach out on the Modal Community Slack.