# kosa8 run

Run a command or script on kosa8 Cloud (serverless), or an image in the local engine

## Usage

```
kosa8 run IMAGE [COMMAND] [ARG...] | run "COMMAND" | run SCRIPT [ARG...]
```

Serverless first: `kosa8 run "COMMAND"` or `kosa8 run script.py` runs on kosa8
Cloud in one call, in a fresh microVM, and prints the output, its cost when the
API reports it, and a link to the run. Not signed in? `kosa8 init` (free
Starter, no card). More below.

With an IMAGE, it runs in kosa8's local engine VM (kosa8 daemon start) rather
than on your host, so the container cannot see your filesystem unless you
mount something into it.

The image is pulled automatically the first time you ask for it. If your
organisation has installed a policy, the registry it comes from must be on
the allowlist or the pull is refused before anything runs.

For work you want to isolate further — a coding assistant, an untrusted
script — put it in its own sandbox instead: `kosa8 sandbox run`.

--cloud runs it on kosa8 Cloud instead: a cloud sandbox of IMAGE runs the
command (with -it, a terminal) and is deleted when it ends. Not signed in, it
runs kosa8 login first.

Serverless: give one quoted command, or a script file (.py, .js, .ts, .sh),
and it runs on kosa8 Cloud in one call (POST /v1/run): a fresh sandbox from
the warm pool, output streamed as it prints, the sandbox deleted after, billed
per second. The language comes from the file's extension. It prints a link to
the run and exits with the command's exit code.

--repo OWNER/NAME[@REF] (or . for this checkout) clones a GitHub repo into the
cloud sandbox first and runs the command in it (kosa8 github connect, once).

## Flags

| Flag | Type | What it does | Default |
|---|---|---|---|
| `--cloud` | bool | run it on kosa8 Cloud instead (signs you in first if needed) |  |
| `--detach, -d` | bool | run in the background and print the container id |  |
| `--env, -e` | stringArray | set an environment variable: KEY=VALUE (repeatable) | `[]` |
| `--github-check` | string | (Next release, not in v0.24.0.) with --repo: put the run's result on the cloned commit as a GitHub check run (named kosa8/run, or --github-check=NAME) |  |
| `--interactive, -i` | bool | keep stdin open |  |
| `--name` | string | assign a name to the container |  |
| `--network` | string | attach to a named network (default: kosa8) |  |
| `--out` | stringArray | serverless run: bring a file back from /workspace into this directory (repeatable) | `[]` |
| `--publish, -p` | stringArray | publish a container port to the host: [HOST:]CONTAINER | `[]` |
| `--quiet, -q` | bool | serverless run: print only the command's own output |  |
| `--repo` | string | (Next release, not in v0.24.0.) kosa8 Cloud: clone this GitHub repo first and run in it: OWNER/NAME[@REF], or . for this checkout (kosa8 github connect first) |  |
| `--rm` | bool | remove the container when it exits (the default for a foreground run) |  |
| `--share` | bool | serverless run: make its run card public (command, output, duration; never env or files) |  |
| `--size` | string | serverless run: sandbox size, vCPU x GiB (0.5x1, 1x2, 2x4, 4x8, …; kosa8 cloud sizes) |  |
| `--template` | string | serverless run: template (default: the language's own) |  |
| `--timeout` | duration | serverless run: stop it after this long (default 60s, at most 1h) | `0s` |
| `--tty, -t` | bool | allocate a pseudo-TTY (implies -i) |  |
| `--upload` | stringArray | serverless run: send a local file along, into /workspace (repeatable) | `[]` |

## Example

```
  kosa8 run "python3 -c 'print(1)'"
  kosa8 run train.py --epochs 3
  kosa8 run --upload data.csv --out chart.png plot.py
  kosa8 run alpine echo hello
  kosa8 run -it alpine sh
  kosa8 run --cloud python:3.12-slim python3 -c 'print(1+1)'
  kosa8 run --repo acme/app@main "npm ci && npm test"   # in a clone of the repo
  kosa8 run --cloud --repo . node:22 npm test             # this checkout's repo and branch
```

---
Source: https://docs.kosa8.com/reference/run/
