Run a Python script 24/7

A script runs around the clock when three things hold: the machine stays on, the process survives your logout, and something restarts it after a crash. An EnvHaven workspace covers the first two by itself; here is the setup, and the other places it can run.

Updated November 23, 2026

A scraper, a price tracker, a trading bot, a job that sends a morning digest: each is a Python script that has to keep running when you are not looking. Three conditions decide whether it does.

  1. The machine stays on. A laptop that sleeps stops the script, and so does any hosted environment that shuts down when idle.
  2. The process survives your logout. Closing a terminal or an SSH session ends the processes started in it, unless they run under tmux, nohup or a service.
  3. Something restarts it. Network errors and exceptions happen; a supervisor or a retry loop brings the script back.

On a workspace

An EnvHaven workspace meets the first two by itself: the machine never sleeps, and its terminal is a tmux session that keeps running when you close the tab. Python 3.12 and uv are ready to use.

  1. Put any keys the script needs in the workspace’s Vars pane; they stay write-only and reach every new shell.
  2. Open a new terminal window and start the script, or ask an agent from the Launch menu to start it in a window of its own.
  3. For the third condition, ask the agent: “Wrap this script so it restarts on any exception and logs to a file.”
  4. Close the tab. The script keeps running while you are away.

A process started in the terminal does not come back by itself after a workspace restart or update, so start the script again after one. If the script needs to be reachable (a webhook receiver, a small dashboard), bind it to 0.0.0.0:3000 and it is live at the workspace’s preview address with HTTPS.

Where it can run

WhereMachine stays onSurvives logoutNotes
An EnvHaven workspaceYesYesPython 3.12, uv and built-in agent support
A VPS you manageYesWith tmux or systemdYou set up everything
A sleeping free tierNoYesStops when idle
Your laptopNoWith tmuxFine for testing

Scheduled jobs

Some jobs only need to run at set times. On a workspace, keep one small loop running that waits for the next run and then calls the script. An agent can write it for you (“run digest.py every day at 07:00 and sleep in between”), and it lives in a terminal window like any other process.

On a server you manage yourself, a cron entry handles it with nothing running in between:

crontab -e
# every day at 07:00
0 7 * * * cd ~/digest && uv run digest.py