# Modal Run

Use when the user asks to run heavy or GPU work on Modal (the cloud compute platform), ...

- Repository: https://github.com/ai4s-research/open-science (2069 stars)
- Category: Writing
- License: see repository
- Last updated: 2026-11-01
- Runs scripts: yes, review before use

## Install

Claude Code: `npx skills add ai4s-research/open-science --skill modal-run -g -a claude-code -y`
Codex: `npx skills add ai4s-research/open-science --skill modal-run -g -a codex -y`
Cursor: `npx skills add ai4s-research/open-science --skill modal-run -g -a cursor -y`
Gemini CLI: `npx skills add ai4s-research/open-science --skill modal-run -g -a gemini-cli -y`

## Description

Use when the user asks to run heavy or GPU work on Modal (the cloud compute platform), writing a Modal function in the workspace, running it with the user's own `modal` CLI + token, and bringing results back. Data-to-compute for jobs too big for the laptop, without a Slurm cluster.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Run compute on Modal

Modal runs code in the cloud on demand (CPU/GPU), billed to the **user's own**
Modal account. Like the HPC/Slurm path, the app never handles credentials, you
use the user's installed `modal` CLI and their token. Prefer local execution or
Slurm first; reach for Modal when the job needs cloud GPUs or elastic scale and
no cluster is available.

## 1 · Check Modal is ready

Modal must be installed and authenticated (the Settings **Cloud compute (Modal)**
card shows this). Verify before writing code:

```bash
modal --version          # installed?
test -f ~/.modal.toml && echo "authenticated" || echo "run: modal token new"
```

If it is not installed, tell the user to `pip install modal`; if not
authenticated, ask them to run `modal token new` in their terminal (it opens a
browser). Do **not** attempt to create or store tokens yourself.

## 2 · Write the Modal function into the workspace

Put the script in the workspace so provenance records it. Pin dependencies in
the image so the run is reproducible, and fix any random seed.

```python
# compute.py, run with:  modal run compute.py
import modal

app = modal.App("open-science-job")
image = modal.Image.debian_slim().pip_install("numpy==1.26.4", "scipy==1.13.1")

@app.function(image=image, gpu=None, timeout=1800)  # set gpu="A10G" etc. if needed
def run(n: int = 1_000_000):
    import numpy as np
    rng = np.random.default_rng(0)          # fixed seed → reproducible
    x = rng.standard_normal(n)
    return {"n": n, "mean": float(x.mean()), "std": float(x.std())}

@app.local_entrypoint()
def main():
    result = run.remote()
    print(result)                            # printed locally; capture it below
```

## 3 · Run it and capture the result

`modal run` executes remotely and streams logs + the local entrypoint's stdout
back. Write the result into a fresh, immutable result directory so it becomes a
traceable artifact and does not overwrite a previous run:

The rest: https://github.com/ai4s-research/open-science/blob/HEAD/runtime/skills/core/modal-run/SKILL.md
