
How do I sign up for Modal and run my first Python function in the cloud (CLI setup steps)?
Quick Answer: Create a free Modal account, install the
modalPython package, runmodal setupto configure your API token, then define a smallmodal.Appwith an@app.functionand execute it in the cloud usingmodal 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 modalandmodal 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
| Concept | Definition | Why it's important |
|---|---|---|
| Modal App | A 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.function | A 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 deploy | CLI 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:
- Create a Modal account.
- Install the CLI and Python SDK.
- Run
modal setupto authenticate with an API token. - Write a tiny
modal.Appin Python. - Execute it in the cloud using
modal run.
Let’s walk through each step.
1. Sign up for Modal
- Go to https://modal.com/signup.
- Create a free account using your email or SSO provider.
- 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
pipavailable
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:
- Open a browser asking you to log in (or confirm the account you just created).
- Generate an API token and store it securely in your local config.
- 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()wrapshelloso 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:
- Inspect your code and build a base image (using Modal’s default Python environment).
- Package your function into that image.
- Spin up a container in the cloud.
- Execute the
hellofunction, 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 deployto 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 runmodal setup,modal runwon’t know which account to use and will fail authentication. Always runmodal setuponce per machine. - Mixing local and remote assumptions: Code inside
@app.functionruns 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:
- Sign up,
pip install modal,modal setup. - Write a small app with an
@app.functionthat loads your model and runs inference. - Use
modal runto test the function in isolation. - Once you’re happy, flip it into a stateful server with
@app.clsand deploy it behind an HTTP endpoint using@modal.fastapi_endpointor@modal.web_server. - 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 runlike you treatpython your_script.py: keep the loop tight. Make a change, runmodal run, inspect logs. Once the behavior is stable, then reach formodal deployand 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:
- Create a free account at modal.com/signup.
- Install the SDK and CLI with
pip install modal. - Authenticate with
modal setup. - Define a
modal.Appand wrap a function with@app.functionin a Python file. - 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.”