A new way to run Python notebooks with Cloudflare
Cloudflare has partnered with the team behind marimo, an open-source reactive Python notebook, to bring a more production-friendly notebook experience to Cloudflare developers. The collaboration introduces Cloudflare authentication directly inside notebooks, ready-to-run examples for Cloudflare services, and the ability to deploy marimo on Cloudflare Containers.
- Cloudflare auth in notebooks: Sign in with a Cloudflare account from within a notebook and use Cloudflare APIs without creating API tokens.
- Open-source examples: Notebook examples cover services including R2, Workers AI, and D1.
- Deploy on Containers: Run marimo notebooks on Cloudflare Containers for long-running, scalable data workflows.
Why marimo differs from traditional notebooks
Traditional notebooks have been the standard for data science and exploration for over a decade, but they were not designed with collaboration, reproducibility, or deployment as data apps in mind. marimo addresses those gaps with a reactive execution model: running a cell or interacting with a UI element executes dependent cells automatically, or marks them as stale, keeping code and outputs consistent and reducing bugs during experimentation.
Because marimo notebooks are stored as Python, they can be versioned with Git, executed as scripts or in pipelines, tested with pytest, and have dependencies managed with inline uv requirements. Notebooks can also be exported to WebAssembly and run in the browser, which makes sharing them essentially free. SQL support is built in, with connections to DuckDB, Postgres, and Iceberg-based catalogs.
Authenticate with Cloudflare from a notebook
Instead of copying and pasting API tokens, notebooks can use a "Sign in with Cloudflare" button powered by PKCE (Proof Key for Code Exchange). This OAuth 2.0 flow avoids client secrets and protects against code interception by generating a one-time code exchanged for a token after login.
The login widget lives in moutils.oauth, a project developed jointly by Cloudflare and marimo. To use it in a notebook, create a cell that invokes the login flow; running the cell displays the sign-in button, and upon completion you receive a read-only access token to use with Cloudflare APIs.
Here is a minimal example to authenticate and list zones you have access to, run locally:
- Install
uvfollowing the installation guide. - Create a directory and initialize a uv project:
mkdir cloudflare-zones-notebook
cd cloudflare-zones-notebook
3. Initialize the project environment:
uv init
4. Add marimo and the required Cloudflare dependencies:
uv add marimo
5. Create a list-zones.py file containing the notebook code:
import marimo
__generated_with = "0.14.10"
app = marimo.App(width="full", auto_download=["ipynb", "html"])
@app.cell
def _():
from moutils.oauth import PKCEFlow
import requests
# Start OAuth PKCE flow to authenticate with Cloudflare
auth = PKCEFlow(provider="cloudflare")
# Renders login UI in notebook
auth
return (auth,)
@app.cell
def _(auth):
import marimo as mo
from cloudflare import Cloudflare
mo.stop(not auth.access_token, mo.md("Please **sign in** using the button above."))
client = Cloudflare(api_token=auth.access_token)
zones = client.zones.list()
[zone.name for zone in zones.result]
return
if __name__ == "__main__":
app.run()
6. Open the notebook editor:
uv run marimo edit list-zones.py --sandbox
7. Complete the OAuth login in the notebook. The final cell displays the list of zones associated with your account.
From there, the notebook can be expanded to call Workers AI models, query Iceberg tables in R2 Data Catalog, or interact with any other Cloudflare API.
Running marimo on Workers and Containers
Sharing a marimo notebook on Cloudflare is straightforward because marimo exports notebooks to WebAssembly. Publishing a notebook to Workers Static Assets requires two commands:
marimo export html-wasm notebook.py -o output_dir --mode edit --include-cloudflare
npx wrangler deploy
For notebooks requiring authentication, Cloudflare Access can be layered on for secure access. Notebooks that need more compute, persistent sessions, or long-running tasks can instead be deployed on Cloudflare Containers; a working example is available in the marimo container example repository.
Start experimenting with the hosted environment at notebooks.cloudflare.com, or review the source code in the notebook examples GitHub repo. This partnership is an initial step toward supporting larger-scale analyses and batch jobs from marimo notebooks in the future.



