Articles

How to run a one-off command in production (a heroku run alternative)

Run migrations and scripts against production in a fresh VM of the live deployment, with its env and secrets, exit codes and timeouts. Compared with heroku run.

Updated

On Gregale, gregale app exec my-api -- <command> runs a one-off command against production, like heroku run: in a fresh VM built from the app's live deployment, with its files, environment variables, secrets and bindings. The output streams back to your terminal and the CLI exits with the command's exit code, so it works in scripts and CI. The VM never serves traffic and is destroyed when the command ends. App tasks are in preview on every plan, Free included.

Run it

bash
# A script from your repository
gregale app exec my-api -- node scripts/backfill.js --since 2026-11-01

# Framework commands
gregale app exec my-api -- python manage.py migrate
gregale app exec my-api -- bin/rails db:seed

# Pipes and variables need a shell
gregale app exec my-api --shell -- 'ls /app | wc -l'

# Stop a runaway command after five minutes
gregale app exec my-api --timeout-seconds 300 -- node scripts/reindex.js
FlagWhat it does
--shellRuns one command string through the app's shell
--timeout-seconds NStops the command after N seconds; the default is 3600
--max-output-bytes NCaps the combined stdout and stderr tail that comes back
--detachReturns as soon as the task is queued
--idempotency-key KEYGives a retried submission the same identity as the first one

What runs where

  • The same code and config as production. The VM boots from the live deployment's image with its environment variables, secrets and database or bucket bindings, so DATABASE_URL points where the app's does.
  • Not on a serving instance. The VM is never routed, parked or snapshotted, and it is destroyed when the command ends. A command that crashes takes no serving instance with it.
  • The exit code comes back. A failing command fails the CLI with the same code; a timeout exits with 124.
  • On a schedule. For a command that runs every night, use a command cron: the same task, on a schedule, with a 10-minute timeout by default.

Interactive shells (gregale app exec my-api -it) are in preview and may not be enabled for your account. The non-interactive commands on this page are what we tested.

What we measured

We ran commands against a Node.js test app on Gregale on 2026-11-28:

  • Time: the first command returned in 5 s; the next three took 1.28, 1.31 and 1.35 s from the CLI's start to its exit.
  • Configuration: the command saw the app's environment, such as its PORT, and the deployment's files under /app.
  • Failures: a command that exited with 3 made the CLI exit with 3; one stopped by --timeout-seconds 5 reported timed_out and exited with 124 after 6 s.

How other platforms compare

PlatformRunning a one-off command in production
Gregalegregale app exec runs it in a fresh VM of the live deployment and returns its output and exit code
Herokuheroku run starts a one-off dyno, billed like any dyno; detached one-off dynos run in the background
RenderOne-off jobs are created through the API with a start command; they use the service's latest build and env vars
Railwayrailway ssh opens a shell in the service's container; railway run runs a command with the service's variables
Fly.iofly ssh console -C runs a command on a running Machine; fly machine run --rm starts a Machine and removes it

Checked against each vendor's public documentation on November 28, 2026: Heroku one-off dynos, Render one-off jobs, Railway CLI, Fly.io ssh console, Fly.io machine run.

Pricing

A one-off command runs in its own VM at the app's memory and is billed like a running instance, per second, from the moment the command starts until it ends, under the app it belongs to. It counts toward your plan's included GB-RAM-hours: Free, Hobby ($10 a month), Pro ($30) and Scale ($99). See Apps, Billing and Gregale pricing.

Questions

What is the Gregale equivalent of heroku run?

gregale app exec my-api -- <command>. It runs the command in a fresh VM built from the app’s live deployment, with its files, environment variables, secrets and bindings, streams the output back and exits with the command’s exit code.

Does a one-off command affect my running app?

It runs in its own VM, which never serves traffic and is destroyed when the command ends, so a command that crashes takes no serving instance with it.

How long can a one-off command run?

An hour by default. Set --timeout-seconds to stop it sooner; a command stopped by its timeout exits with 124.

Is a one-off command billed?

Yes, like a running instance: per second at the app’s memory, from the moment the command starts until it ends, under the app it belongs to.