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)?

7 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 small modal.App with an @app.function and execute it in the cloud using modal run your_file.py. The whole flow—from signup to seeing your first Python function run on Modal’s servers—takes just a few minutes.

Why This Matters

If you’re building AI-heavy workloads, local machines and traditional servers hit a wall fast: you run out of GPU, you blow your latency budget, or you spend days wiring up Docker, Kubernetes, and YAML just to run one function at scale. Modal lets you skip that overhead. You define your environment and hardware in Python, hit modal run or modal deploy, and Modal handles containers, autoscaling, and execution across CPUs/GPUs in the cloud.

Key Benefits:

  • Fast path to the cloud: Go from a local Python script to running in the cloud in minutes using just pip install modal and modal setup.
  • Code-defined infrastructure: Define your app, runtime image, and functions in Python code instead of scattered config files.
  • Production-ready from day one: The same primitives (@app.function, .remote(), modal deploy) you use for a toy function scale to GPU inference, batch jobs, and scheduled workloads.

Core Concepts & Key Points

ConceptDefinitionWhy it's important
Modal AppA Python object (modal.App) that groups functions, classes, and resources into a deployable unit.It’s the root of everything you deploy; it defines the boundary of your cloud app.
@app.functionA decorator that turns a plain Python function into a containerized, remotely executable function on Modal.This is how you tell Modal “run this code in the cloud,” with scaling, logging, and timeouts handled for you.
modal run / modal deployCLI commands to execute or deploy your Modal app from a Python file or module.They’re your main workflows: experiment locally with modal run, then ship durable services with modal deploy.

How It Works (Step-by-Step)

At a high level, you:

  1. Create a Modal account.
  2. Install the CLI and Python SDK.
  3. Run modal setup to authenticate with an API token.
  4. Write a tiny modal.App in Python.
  5. Execute it in the cloud using modal run.

Let’s walk through each step.

1. Sign up for Modal

  1. Go to https://modal.com/signup.
  2. Create a free account using your email or SSO provider.
  3. Once you’re in, you’ll land on the Modal dashboard where you can later see logs, running apps, and resources.

You don’t need a credit card to get started. The goal is to get you running code, not filling out forms.

2. Install the Modal Python package and CLI

On your local machine (macOS, Linux, WSL, etc.), make sure you have:

  • Python 3.8+ installed
  • pip available

Then install Modal:

pip install modal

This installs both:

  • The Python SDK you import in your code (import modal)
  • The CLI you use from the shell (modal ... commands)

You can verify the install with:

modal --help

If you see help text, you’re good.

3. Configure the CLI with modal setup

Next, you need to authenticate the CLI so it can talk to your Modal account.

Run:

modal setup

This will:

  1. Open a browser asking you to log in (or confirm the account you just created).
  2. Generate an API token and store it securely in your local config.
  3. Link your local machine to your Modal account.

Under the hood, this is just setting up auth so modal run and modal deploy know who you are and which account to use.

If your browser doesn’t open automatically, the CLI will print a URL you can paste into your browser.

4. Write your first Modal App and function

Now let’s write a minimal Python script that runs a function in the cloud.

Create a file called hello_modal.py:

import modal

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

# 2) Turn a Python function 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!"

What this does:

  • app = modal.App("example-get-started") defines an app. The string is just a human-friendly name.
  • @app.function() wraps hello so Modal knows it should package this function into an image and run it in a container.
  • The function itself is regular Python—you can import other libraries, call APIs, etc.

At this point you’ve defined infrastructure entirely in code:

  • The app boundary: modal.App(...)
  • The unit of execution: @app.function

No Dockerfile, no YAML, no manual container builds.

5. Run your function in the cloud with the CLI

With hello_modal.py saved, run:

modal run hello_modal.py

On the first run, Modal will:

  1. Inspect your code and build a base image (using Modal’s default Python environment).
  2. Package your function into that image.
  3. Spin up a container in the cloud.
  4. Execute the hello function, printing logs to your terminal.

You should see something like:

Running in the cloud, saying hi to world

By default, if you call modal run on a file with a single app and a single function, Modal will run an entrypoint main (or walk you through if multiple entrypoints are present). For more control, you can explicitly specify the function:

modal run hello_modal.py::hello

You can pass arguments from the CLI too:

modal run hello_modal.py::hello --name Erik

From here, the next steps are:

  • Use .remote() in your Python code to invoke Modal functions programmatically.
  • Use modal deploy to turn this into a long-lived service with web endpoints.

But you already have a full end-to-end “run a Python function in the cloud” loop.

Common Mistakes to Avoid

  • Skipping modal setup: If you install the package but don’t run modal setup, modal run won’t know which account to use and will fail authentication. Always run modal setup once per machine.
  • Mixing local and remote assumptions: Code inside @app.function runs in a container, not on your laptop. Don’t assume access to your local filesystem or environment variables unless you explicitly wire them up (e.g., using Modal Volumes or Secrets).

Real-World Example

Let’s say you’re prototyping an AI workload that needs to hit an open‑source model on GPU sporadically throughout the day. Locally you can’t run the model at all, and you don’t want to rent a GPU instance that idles 95% of the time.

You’d start exactly like this post:

  1. Sign up, pip install modal, modal setup.
  2. Write a small app with an @app.function that loads your model and runs inference.
  3. Use modal run to test the function in isolation.
  4. Once you’re happy, flip it into a stateful server with @app.cls and deploy it behind an HTTP endpoint using @modal.fastapi_endpoint or @modal.web_server.
  5. Let Modal autoscale GPUs up when requests spike and back to zero when idle, while you just call a URL.

The initial “hello world” is the same pattern, just without the model and HTTP layer.

Pro Tip: Treat modal run like you treat python your_script.py: keep the loop tight. Make a change, run modal run, inspect logs. Once the behavior is stable, then reach for modal deploy and more advanced constructs like retries, Volumes, and GPU types.

Summary

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

  1. Create a free account at modal.com/signup.
  2. Install the SDK and CLI with pip install modal.
  3. Authenticate with modal setup.
  4. Define a modal.App and wrap a function with @app.function in a Python file.
  5. Execute it in the cloud using modal run your_file.py.

That’s the core loop: code-defined infrastructure, a single CLI, and a fast path from “I have a function” to “this is running in a container with logs and autoscaling baked in.”

Next Step

Get Started