# Commands

> Run a command once in your app, such as a migration or a script, on a machine of its own from the live version, and read its output as it prints.

The **Commands** tab of an app runs a command once: a migration you want to run by hand, a script that fixes some data, a quick look at what the app sees. The command runs on a machine of its own, made from the version of the app that is live, and its output shows on the page as it prints. The machine is removed when the command ends.

## Run a command

Open the app, **Commands**, type the command in the box and press **Run**. It is one line, run from the root directory of the app, such as `node scripts/seed.js` or `npm run db:migrate`. A script in your repository can hold more.

Under the box, the page says what a command costs: a machine of the app's size while it runs, counted by the second.

The run appears at the top of the list and opens below it. Its output follows while it runs. When it ends, the page shows how it ended, its exit code and how long it took.

## How a command runs

- **On a machine of its own.** Each command starts a fresh machine of the [size and region](https://arrangic.com/docs/scaling.md) of the app, from the image of the live version, with the app's [environment variables](https://arrangic.com/docs/environment-variables.md). Replicas of the app are not touched, and a sleeping app stays asleep.
- **Without root rights,** like the app itself. The command can write in the folder of the app, in the home folder and in `/tmp`. Nothing it writes is kept: the machine is removed when the command ends. Data belongs in a database or a store outside the app.
- **In the folder of the app**, or inside `build` for an [AdonisJS](https://arrangic.com/docs/frameworks/adonisjs.md) app, where the build writes `ace`.
- **Without input.** Nothing can be typed into a running command. A command that asks a question, or a console that waits for input, waits until it is stopped. Give it flags that answer for it, such as `--force` or `--yes`.
- **For up to 15 minutes.** A command that takes longer is stopped with "The command did not finish within 15 minutes and was stopped."
- **As a script that starts with `set -e`.** A part of the line that fails ends the run with its exit code: `false; echo ok` ends with exit code 1 and prints nothing. The shell and the time limit are started by their full path, so a `PATH` variable of yours changes which programs your command finds, not how it is started or stopped.
- **Its output through the logs.** What the command prints is read from the app's logs while it runs. Printed at a normal pace, every line arrives. A command that prints hundreds of lines within a second can have some of them left out, so send a long report to a database or a store of your own rather than to the screen. Where the output holds the value of one of the app's [variables](https://arrangic.com/docs/environment-variables.md), it shows `[hidden]` in its place.

## Who can run a command

The owner and the admins of the team. A member sees the tab, the runs and what they printed, and may **Stop** a run; for them the box is greyed out with "Only team admins can run commands." See [Teams](https://arrangic.com/docs/teams.md#roles).

## Stop and run again

**Stop** ends a command that is still going. What it printed so far is kept, and the run says who stopped it. **Run again** runs the command of an ended run once more, as a new run.

## When a command is refused

The box says why when a command cannot run:

| Reason | What to do |
| --- | --- |
| The app is paused | [Resume](https://arrangic.com/docs/deployments.md#pause-and-resume) the app |
| No version is deployed yet | Deploy the app once |
| Three commands are already running | Wait for one to end, or stop one |
| The plan does not allow running apps | Choose a plan under **Team settings**, **Billing** |
| Builds are paused for maintenance right now. Try again in a little while. | Commands start again when builds resume. Try again later |
| A command is one line. Put several commands in a script and run that. | Run one line, or a script from your repository |
| The command contains characters that cannot be used. | The line holds a control character, an invisible character or bytes that are not UTF-8. Type it again |

A command must be one line and cannot start with a dash. Software the [acceptable use policy](https://arrangic.com/acceptable-use) does not allow, such as a miner, is refused.

## What is kept

The last 50 commands of an app are listed, each with who ran it, how it ended, its exit code, how long it took and what it printed (the last 64 KB; earlier lines are replaced by "[earlier output left out]"). The team's activity shows who ran or stopped which command.

## What it costs

A command is counted like a replica: by the second, at the price of the app's size and region, only while it runs. It uses the size the live version runs at: a new size you saved waits for the next deployment. On the bill it is not part of the app's compute: it is on the line **Jobs and commands**, outside the compute cap shown under **Scaling**. See [Billing](https://arrangic.com/docs/billing.md#what-is-counted).

## Limits

- Three commands running at a time per app.
- 15 minutes per command.
- The last 50 commands of an app are kept, with the last 64 KB of output each.

## Commands or something else

- Work that has to happen on every deployment, such as migrations, belongs in [deploy commands](https://arrangic.com/docs/deploy-commands.md).
- Work that repeats on a schedule belongs in a [cron job](https://arrangic.com/docs/cron-jobs.md).
- A command that keeps running, such as a queue worker, belongs in a [worker](https://arrangic.com/docs/workers.md).

---

This page on the site: https://arrangic.com/docs/commands  
All pages of the documentation: https://arrangic.com/llms.txt
