---
title: "Run a cron job over MCP with no server, with while.sh"
url: https://while.sh/en/guides/run-cron-job/
author: "Aloïs Oddon, co-founder of Nextmap"
updated: 2026-11-02
---

# Run a script on a schedule from your AI agent, with no server

A report every morning, an import every night? Tell your agent the time: connected to while over MCP, it schedules your script, and you always know whether it ran.

## Prerequisites

- A Python, Node.js or Go script, with its requirements.txt, its package.json or its go.mod: your agent adds it if it's missing.
- An AI agent that works in a terminal: Claude Code, Codex, Cursor or Gemini CLI.

## Step 1: Give your agent these instructions

Open your agent in your script's folder, and paste these instructions into it:

```text titre="Instructions"
Connect to while with my account (while.sh/agents), then deploy my app.
```

Your agent adds while's MCP server itself. If it asks you to, restart it. On the first call to while, a page opens in your browser. In Claude Code, if it doesn't open, type /mcp, choose while, then Authenticate. On that page, choose "A new app", then click Authorize.

## Step 2: Follow the runs

Your agent tells you when the script will run, and gives you the result of each run.

## What your agent does

It writes while.yaml next to your script:

```yaml titre="while.yaml"
apiVersion: while/v1
project: mon-script
crons:
  - name: rapport
    schedule: "0 7 * * *"
    timezone: Europe/Paris
    command: [python, rapport.py]
    source: .
```

The schedule reads in one line: `0 7 * * *` means every day at 7 am (source 1). A run that ends with exit code 0 has succeeded.

## Run the script right now

> You, to your agent: Run the report now.

Your agent starts a run without waiting for the scheduled time, and gives you its result.

## Know whether everything went well

> You, to your agent: Did this morning's report go out?

Every run is recorded with its duration, its exit code and the last lines of its log. A run that fails or is missed alerts your agent.

## Catch up on a missed period

> You, to your agent: Rerun the import for the last three days.

Your agent reruns the job over that period: your script receives its start and end dates, and your agent writes it to process only those dates.

## Add a database

> You, to your agent: Add a PostgreSQL database.

Your agent declares the database in while.yaml, and its address reaches your code in `DATABASE_URL`. It's backed up every day, and can go back to a precise moment if needed.

## Next steps

- [Deploy a Node.js API and its PostgreSQL database](/en/guides/deploy-node-api-postgresql/)
- [Add a Redis-compatible cache](/en/guides/add-redis-cache/)
- [Compare the hosts that have an MCP server](/en/comparisons/mcp-hosting-claude-code/)

## Sources

1. [The Linux manual, crontab(5), the five fields of a cron line](https://man7.org/linux/man-pages/man5/crontab.5.html), 2026-11-01

## Questions

### Can my script read my app's database?

Yes, it receives the same variables as your app, database address included.

### Who can open my script from the internet?

Nobody: a scheduled job has no public address.

### In which time zone?

The one you choose, Paris time by default.
