# runlinux

> Run a shell script on a cloud Linux builder with JDK 21 and the Android SDK, such as Gradle tasks, and bring back the files you name.

Source: https://air.build/docs/cli/runlinux/

`runlinux` runs one Bash script on a Linux builder, from a Team's Environment. It needs no `airbuild.yaml`. It is the Linux counterpart of [runmacos](https://air.build/docs/cli/runmacos/): the same options, its own slot.

The builder has JDK 21, the Android SDK and a warm `~/.gradle`, so it suits Gradle tasks such as `./gradlew lint` or `./gradlew dependencies`, and other Linux tools the sandbox lacks. It has **no Node or Bun**: install them in the script, or use `runmacos`, which has Node, npm and pnpm. There is no `airbuild-xcode` here.

It is for **cloud Teams only**. On a Mac Team it stops with `runlinux is only available in cloud Teams; local Teams provide runtest.`

To build or test an Android app, use `runbuild --platform android_beta` and `runtest --platform android_beta`; `runlinux` is for everything else.

## Synopsis

```bash
runlinux [<project-id>] [--source <directory>] [--output <relative-path>]... --command '<shell script>' [--environment ID] [--no-cache]
runlinux --follow [--run ID]    # reattach; starts nothing
runlinux --cancel [--run ID]
runlinux --list-environments
runlinux --help
```

## Options

| Option | Value | Default | What it does |
| --- | --- | --- | --- |
| `--command` | shell script | required | The Bash script to run, at the uploaded root, with `-e -o pipefail`. |
| `<project-id>` | UUID | none | Upload this Project and run at its root. |
| `--source` | directory | none | Upload this directory instead. Relative to your current directory. With both, `--source` is what is uploaded. |
| `--output` | relative path | none | A file or directory to bring back. Repeat for more. |
| `--environment` | ID from `--list-environments` | the first Linux environment | Run on another Linux environment. One for another platform is refused. |
| `--no-cache` | — | caches on | Turns `airbuild-cache restore` and `save` off for this run. |
| `--follow` | — | — | Reattaches to a run already in progress. On a finished run, says so and replays its saved output. |
| `--run` | run ID | the running run, else the newest | With `--follow` or `--cancel`. |
| `--cancel` | — | — | Asks the run to stop; waits up to 30 seconds for confirmation. |
| `--list-environments` | — | — | Lists the builder environments. |

Without a Project ID or `--source`, the script runs in an empty directory and no source is uploaded.

## Caches

Nothing is cached on its own except the warm `~/.gradle`. To keep files between runs (`node_modules`, a package store, Gradle's build cache), restore them in the script with [airbuild-cache](https://air.build/docs/cli/airbuild-cache/):

```bash
airbuild-cache restore --key node --path node_modules
```

Whatever the script restored is saved again after it ends, every time, and uploads after the result is back. Linux and macOS builders keep separate entries under the same key.

## Outputs and results

`--output` paths follow the same rules as [runmacos](https://air.build/docs/cli/runmacos/): concrete, relative, no `..`, wildcards, symbolic links or overlapping paths. A failed script still brings back the outputs that exist, with its exit code. The run ends the same way:

```text
✓ Command finished.
  Build: <build-id>
  Artifact: <path to the collected outputs>
```

## Exit codes

| Code | Meaning |
| --- | --- |
| `0` | The script passed and every output was written. |
| `1` | The run could not start or was lost. |
| `2` | A wrong option, or `--command` missing; nothing ran. |
| `65` | A declared output is missing or cannot be exported. |
| `130` | Canceled, or detached with Ctrl-C. |
| other | The script's own exit code. |

## Errors

| Message | What to do |
| --- | --- |
| `--command requires a nonempty shell script and is only available with runmacos and runlinux.` | Pass a script. |
| `--platform takes a platform (…) and is only available with runbuild and runtest.` | Drop `--platform`. |
| `runlinux does not accept build or signing options.` | Drop `--sign` / `--unsigned`. |
| `Declared output was not produced: <path>` | Make the script write it, or drop the `--output`. |
| `N runlinux executions are running; choose one with --run.` | Pass one of the run IDs it lists. |
| `This Team's Environment is already running N runlinux executions, the limit.` | Wait for one to finish, or follow one. |

A script that calls `node` or `bun` without installing them fails with `command not found` (exit 127).

## Examples

```bash
# List the app's dependencies and bring the list back
runlinux 3f6c1a2e-8b4d-4f0a-9c1e-2d7b5a6e9f10 \
  --command './gradlew dependencies > dependencies.txt' --output dependencies.txt
```

```bash
# Keep a downloaded tools directory between runs
runlinux 3f6c1a2e-8b4d-4f0a-9c1e-2d7b5a6e9f10 --command '
  airbuild-cache restore --key tools --path .tools
  ./scripts/fetch-tools.sh .tools'
```

```bash
# What the builder has
runlinux --command 'java -version; ls "$ANDROID_HOME"'
```
