How do I sign up for Modal and run my first Python function in the cloud (CLI setup steps)?
Platform as a Service (PaaS)

How do I sign up for Modal and run my first Python function in the cloud (CLI setup steps)?

6 min read

Quick Answer: Create a free Modal account, install the modal Python package, run modal setup to configure your API token, then define a modal.App with an @app.function and execute it using modal run your_file.py. You’ll have a Python function running in the cloud in just a few minutes.

Why This Matters

If you’re building AI workloads, you don’t have time to babysit servers or fight with YAML just to run a simple function on a GPU. Getting set up on Modal via the CLI gives you a fast path from “local script” to “cloud function” with sub-second cold starts, autoscaling, and zero infrastructure glue. Once your first function runs, the same pattern scales to production endpoints, batch jobs, and GPU-heavy model serving.

Key Benefits:

  • Fast setup from local to cloud: Go from pip install to a cloud-executed function with a few commands and one decorator.
  • Code-defined infrastructure: Hardware, environment, and scaling live in Python, not scattered configs or dashboards.
  • Production-ready from day one: The same primitives you use for a hello-world function—App, @app.function, modal run, modal deploy—are how you ship real workloads.

Core Concepts & Key Points

ConceptDefinitionWhy it's important
Modal AppA Python object (modal.App) that groups functions, classes, and endpoints into a deployable unit.It’s the basic unit of deployment: you inspect logs, scale, and manage resources at the App level.
@app.functionA decorator that turns a regular Python function into a cloud-executed function running in a container.This is how you get from “local function” to scalable, autoscaled cloud execution without changing your function body.
CLI workflow (modal run / modal deploy)Commands that run code once (modal run ...) or deploy long-lived apps and endpoints (modal deploy ...).Keeps feedback loops tight: experiment interactively, then promote to production without rewriting your code.

How It Works (Step-by-Step)

Here’s the full end-to-end path: sign up, install the CLI, configure auth, then run a real Python function on Modal.

1. Sign up for a free Modal account

  1. Go to https://modal.com/signup.
  2. Create your account (GitHub or email).
  3. Once you’re in the dashboard, keep the browser tab open—you’ll use it to verify that your app and logs exist after running your first function.

2. Install the Modal Python package

You’ll need Python (3.x) and pip installed locally.

pip install modal

If you use virtual environments (recommended), activate one before installing:

python -m venv .venv
source .venv/bin/activate  # on macOS/Linux
# or
.\.venv\Scripts\activate   # on Windows

pip install modal

3. Configure the CLI and create an API token

Run the setup command once; it will guide you through authentication:

modal setup

What modal setup does:

  • Opens a browser for you to log in (or re-use your existing session).
  • Creates an API token tied to your account.
  • Stores credentials locally so the CLI and SDK can talk to the Modal control plane.

You can verify the CLI works by running:

modal --help

4. Write your first Modal App in Python

Create a new file, for example hello_modal.py:

import modal

# 1) Create a Modal App
app = modal.App("example-get-started")


# 2) Turn this into a cloud function
@app.function()
def hello(name: str = "world") -> str:
    print(f"Running in the cloud, saying hi to {name}")
    return f"Hello, {name} from Modal!"

A few things happening here:

  • app = modal.App("example-get-started")
    Creates an App named example-get-started that will show up in your Modal dashboard.
  • @app.function()
    Tells Modal: “run this function in a container in the cloud when invoked.”

You didn’t specify hardware, images, or scaling yet; Modal will use sensible defaults. You can tighten those later (e.g., pinning Python version, adding system packages, GPUs, etc.).

5. Run your function in the cloud via CLI

You can execute the function once with modal run. Under the hood, Modal will:

  • Package your code and dependencies.
  • Build an image for your function.
  • Schedule it on Modal’s compute.
  • Stream logs and results back.

Run:

modal run hello_modal.py::hello

Explanation:

  • hello_modal.py is your script.
  • ::hello tells Modal which function in that file to run.

You’ll see logs printed in your terminal, something like:

Running in the cloud, saying hi to world

If you want to override the name argument:

modal run hello_modal.py::hello --arg name=Modal

Check your Modal dashboard (Apps page). You should see the example-get-started app with run history and logs.

6. Optional: Run an example from the Modal repo

If you want to sanity-check your setup with an official example:

git clone https://github.com/modal-labs/modal-examples
cd modal-examples

modal run 10_integrations/cron_datasette.py

This will execute a sample app maintained by the Modal team, using the same path you’ll use for your own code.

7. From single runs to deployed apps

Once you’re comfortable with modal run, the next step is to deploy long-lived apps—like HTTP endpoints or periodic jobs:

modal deploy hello_modal.py

This turns your App into a deployed service. From here, you can:

  • Stream logs for the deployed app:

    modal app list           # see your apps
    modal app logs example-get-started
    
  • Add more functions, classes, and endpoints to the same App and redeploy.

You don’t have to deploy for one-off runs, but it’s the path to building proper services.

Common Mistakes to Avoid

  • Skipping modal setup:
    Trying to run modal run before authenticating leads to confusing auth errors. Always run modal setup once after installation.

  • Forgetting the @app.function decorator:
    Defining a function without decorating it (def hello(...):) won’t expose it to Modal. Make sure every function you want to run in the cloud is decorated with @app.function() and belongs to an App.

Real-World Example

Imagine you’re prototyping a batch image-processing pipeline. Locally, you’ve got:

def resize_image(path: str) -> None:
    ...

To fan this out to hundreds of images in parallel on Modal, you’d:

import modal

app = modal.App("image-resizer")


@app.function()
def resize_image(path: str) -> None:
    # Your existing resize code goes here
    print(f"Resizing {path}")
    # write result to cloud storage, etc.


if __name__ == "__main__":
    import sys

    # simple local driver
    paths = sys.argv[1:]
    # fan out across many containers
    list(resize_image.map(paths))

Then you run:

modal run image_resizer.py --arg paths=img1.jpg,img2.jpg,img3.jpg

Modal will spin up as many containers as needed to keep your concurrency high and throughput up, without you managing a single VM or GPU reservation.

Pro Tip: Treat modal run as your “cloud REPL.” Use it early and often while iterating—once the behavior is what you want, wire the same functions into endpoints (@modal.fastapi_endpoint), schedules (modal.Cron / modal.Period), or batch jobs without rewriting infrastructure code.

Summary

To sign up for Modal and run your first Python function in the cloud via the CLI, you:

  1. Create a free account at Modal.
  2. Install modal with pip install modal.
  3. Run modal setup to configure your API token.
  4. Define a modal.App and decorate a function with @app.function.
  5. Execute it in the cloud using modal run your_file.py::your_function.

From there, the same pattern scales from “hello world” to GPU-heavy inference, batch processing, and stateful model servers—still defined in Python, still controlled from the CLI.

Next Step

Get Started