# Commands and jobs

Run a program in your VM and read its output, open an interactive terminal, and start background jobs you can list, read, wait for and stop.

Source: https://slashinfra.com/docs/platform/commands-and-jobs
Last modified: 2026-11-30T16:36:19.000Z

A command runs one program in your VM and returns its output and exit code when it ends. A background job keeps running after the request that started it ends, so work longer than the command timeout can finish.

The examples use a VM named `runner`. Set `VM` to its id and `SI_API_KEY` to a key from [API keys](https://app.slashinfra.com/keys):

```bash
export VM=6f1c0f0e8a
export SI_API_KEY=si_...
```

## Run a command

[`POST /{path}`](https://slashinfra.com/docs/api-reference/svm#runProgram) runs the program at the path in the VM. The request body is its standard input, and the reply is standard output and standard error together. `si exec` sends the same request.

Each request starts a new process as `user` in `/home/user`. A `cd` or `export` in one request does not carry into the next, so keep state in files. The command below writes a file that the job reads below.

### CLI

```bash
si exec runner -- tee /home/user/notes.txt <<'EOF'
alpha
beta
gamma
delta
EOF
```

Output

```text
alpha
beta
gamma
delta
```

### curl

```bash
curl -sS -i -X POST "https://$VM.slashinfra.dev/usr/bin/tee?arg=/home/user/notes.txt" \
-H "Authorization: Bearer $SI_API_KEY" --data-binary $'alpha\nbeta\ngamma\ndelta\n'
```

Output

```text
HTTP/2 200
X-Exit-Code: 0
...
alpha
beta
gamma
delta
```

### Python

```python
import os, requests

res = requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/tee",
params={"arg": "/home/user/notes.txt"},
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
data=b"alpha\nbeta\ngamma\ndelta\n",
)
res.raise_for_status()
print(res.text, end="")
print(res.headers["X-Exit-Code"])
```

Output

```text
alpha
beta
gamma
delta
0
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/usr/bin/tee?arg=/home/user/notes.txt`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
body: 'alpha\nbeta\ngamma\ndelta\n',
})
if (!res.ok) throw new Error(await res.text())
process.stdout.write(await res.text())
console.log(res.headers.get('X-Exit-Code'))
```

Output

```text
alpha
beta
gamma
delta
0
```

A failed program is still an HTTP success. The exit code is in `X-Exit-Code`, and `si exec` exits with the same code.

```bash
curl -sS -i -X POST "https://$VM.slashinfra.dev/bin/bash" \
-H "Authorization: Bearer $SI_API_KEY" \
--data-binary 'echo "no such report" >&2; exit 1'
```

Output

```text
HTTP/2 200
X-Exit-Code: 1
...
no such report
```

A file without the executable bit answers 403 `svm: /path: Permission denied`. Set the bit with `si exec runner -- chmod +x /home/user/report.sh`.

`timeout` is 1 to 30 seconds and 30 by default. At the timeout the API ends the process group and returns the output so far, with `X-Timeout: 1` and exit code 124.

```bash
curl -sS -i -X POST "https://$VM.slashinfra.dev/bin/sleep?arg=60&timeout=5" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
HTTP/2 200
X-Exit-Code: 124
X-Timeout: 1
...
```

### Stream the output

Send `Accept: text/event-stream` to read output as it arrives. Each `stdout` or `stderr` event carries one JSON-encoded chunk, and bytes that are not UTF-8 arrive as `{"encoding":"base64","data":"..."}`. The last event is `exit`, with `code` and `timed_out`. A stream has no 1 MiB output cap and keeps the VM awake while it runs.

### curl

```bash
curl -sSN -X POST "https://$VM.slashinfra.dev/bin/bash" \
-H "Authorization: Bearer $SI_API_KEY" -H "Accept: text/event-stream" \
--data-binary 'echo first; sleep 1; echo second'
```

Output

```text
event: stdout
data: "first\n"

event: stdout
data: "second\n"

event: exit
data: {"code":0,"timed_out":false}
```

### Python

```python
import os, requests

with requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/bin/bash",
headers={
"Authorization": f"Bearer {os.environ['SI_API_KEY']}",
"Accept": "text/event-stream",
},
data=b"echo first; sleep 1; echo second",
stream=True,
) as res:
res.raise_for_status()
for line in res.iter_lines(decode_unicode=True):
if line:
print(line)
```

Output

```text
event: stdout
data: "first\n"
event: stdout
data: "second\n"
event: exit
data: {"code":0,"timed_out":false}
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/bin/bash`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SI_API_KEY!}`,
Accept: 'text/event-stream',
},
body: 'echo first; sleep 1; echo second',
})
if (!res.ok || !res.body) throw new Error(`run failed: ${res.status}`)
const reader = res.body.getReader()
const decoder = new TextDecoder()
for (;;) {
const { done, value } = await reader.read()
if (done) break
process.stdout.write(decoder.decode(value, { stream: true }))
}
```

Output

```text
event: stdout
data: "first\n"

event: stdout
data: "second\n"

event: exit
data: {"code":0,"timed_out":false}
```

## Open an interactive terminal

A terminal is a WebSocket to `/bin/{program}`. Binary frames carry terminal input and output in both directions, and a text frame `{"cols":80,"rows":24}` resizes the terminal. Use it for an interactive shell, a full-screen program or an agent. `si shell` needs an interactive terminal; a pipe or a script uses `si exec`.

Without `Upgrade: websocket`, [`GET /bin/{program}`](https://slashinfra.com/docs/api-reference/svm#openTerminal) returns the terminal page or the program file, and opens no terminal. Closing the connection ends the program unless it is an `hc` terminal. A keystroke keeps an `auto` VM awake for 5 minutes; an open terminal alone does not.

### Dashboard

- Open [SVMs](https://app.slashinfra.com/svms) and select `runner`. 
- Select Terminal. A terminal to the VM opens in a new tab. 
- Run `hostname`. The prompt shows the VM’s id. 
- Run `exit` to close the terminal.

### CLI

```bash
si shell runner
```

Output

```text
user@6f1c0f0e8a:~$ hostname
6f1c0f0e8a
user@6f1c0f0e8a:~$ exit
logout
```

`--program` chooses `bash` (the default), `zellij`, `tmux` or `herdr` from the CLI. The API also accepts `hc`, `claude`, `codex` and `opencode`, and passes an agent’s options in up to 16 `arg` values.

## Start a background job

A job runs a program after the request that started it ends. [`POST /usr/bin/job`](https://slashinfra.com/docs/api-reference/svm#runProgram) runs the VM’s `job` program: the body is a script, and `arg=-q` prints the job number alone. `si job start` sends the script and prints the number.

The job writes its standard output and error to `/var/log/jobs/<number>.log`.

### CLI

```bash
si job start runner -c 'while read line; do echo "checking $line"; sleep 5; done < /home/user/notes.txt'
```

Output

```text
1
```

### curl

```bash
curl -sS -i -X POST "https://$VM.slashinfra.dev/usr/bin/job?arg=-q" \
-H "Authorization: Bearer $SI_API_KEY" \
--data-binary 'while read line; do echo "checking $line"; sleep 5; done < /home/user/notes.txt'
```

Output

```text
HTTP/2 200
Location: /var/log/jobs/1.log
X-Exit-Code: 0
...

1
```

### Python

```python
import os, requests

res = requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/job",
params={"arg": "-q"},
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
data=b'while read line; do echo "checking $line"; sleep 5; done < /home/user/notes.txt',
)
res.raise_for_status()
print(res.text, end="")
```

Output

```text
1
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/usr/bin/job?arg=-q`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
body: 'while read line; do echo "checking $line"; sleep 5; done < /home/user/notes.txt',
})
if (!res.ok) throw new Error(await res.text())
process.stdout.write(await res.text())
```

Output

```text
1
```

The job prints `checking alpha` at once, then one line every 5 seconds. Its log is at `/var/log/jobs/1.log`.

## List jobs

List returns every job of the VM, newest first, with its state, exit code, leader PID, CPU seconds, peak memory, start time and command. `STATE` is `running`, `exited`, `killed` or `oom`.

### CLI

```bash
si job ls runner
```

Output

```text
JOB  STATE  CODE  PID  CPU_S  MEM_MIB  STARTED  COMMAND
1  running  -  46  0.00  0.9  2026-11-29T13:42:21Z  while read line; do echo "checking $line"; sleep 5; done < /home/user/notes.txt
```

### curl

```bash
curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/job?arg=ls" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
JOB  STATE  CODE  PID  CPU_S  MEM_MIB  STARTED  COMMAND
1  running  -  44  0.00  0.9  2026-11-29T13:38:09Z  while read line; do echo "checking $line"; sleep 5; done < /home/user/notes.txt
```

### Python

```python
import os, requests

res = requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/job",
params={"arg": "ls"},
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(res.text, end="")
```

Output

```text
JOB  STATE  CODE  PID  CPU_S  MEM_MIB  STARTED  COMMAND
1  running  -  48  0.00  0.7  2026-11-29T13:38:59Z  while read line; do echo "checking $line"; sleep 5; done < /home/user/notes.txt
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/usr/bin/job?arg=ls`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(await res.text())
process.stdout.write(await res.text())
```

Output

```text
JOB  STATE  CODE  PID  CPU_S  MEM_MIB  STARTED  COMMAND
1  running  -  48  0.00  0.7  2026-11-29T13:39:40Z  while read line; do echo "checking $line"; sleep 5; done < /home/user/notes.txt
```

## Read the log

The log is at `/var/log/jobs/<number>.log` in the VM. It holds standard output and standard error, and it grows while the job runs. Add `--follow` to keep printing new lines until the job ends.

### CLI

```bash
si job logs runner --follow 1
```

Output

```text
checking alpha
checking beta
checking gamma
checking delta
```

### curl

```bash
curl -sS "https://$VM.slashinfra.dev/var/log/jobs/1.log" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
checking alpha
checking beta
```

### Python

```python
import os, requests

res = requests.get(
f"https://{os.environ['VM']}.slashinfra.dev/var/log/jobs/1.log",
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(res.text, end="")
```

Output

```text
checking alpha
checking beta
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/var/log/jobs/1.log`, {
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(await res.text())
process.stdout.write(await res.text())
```

Output

```text
checking alpha
checking beta
```

A job still running at a sleep on disk shows `killed` with code 137 after the wake, because its process ended and it has no exit record. Its log and job number stay. A sleep in memory keeps the process running.

## Wait for the end

Wait blocks until the job ends and returns its exit code and run time. A signal reports `killed` with 128 + the signal. A job still running when its VM ended reports `killed` with 137. A job that has ended returns at once.

### CLI

```bash
si job wait runner 1
```

Output

```text
job 1 exited: code 0, 20.0s
```

### curl

```bash
curl -sS -i -X POST "https://$VM.slashinfra.dev/usr/bin/job?arg=wait&arg=1&timeout=30" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
HTTP/2 200
X-Exit-Code: 0
...
job 1 exited: code 0, 20.0s
```

### Python

```python
import os, requests

res = requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/job",
params={"arg": ["wait", "1"], "timeout": 30},
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(res.text, end="")
print(res.headers["X-Exit-Code"])
```

Output

```text
job 1 exited: code 0, 20.0s
0
```

### TypeScript

```ts
const url = new URL(`https://${process.env.VM!}.slashinfra.dev/usr/bin/job`)
url.searchParams.append('arg', 'wait')
url.searchParams.append('arg', '1')
url.searchParams.set('timeout', '30')

const res = await fetch(url, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(await res.text())
process.stdout.write(await res.text())
console.log(res.headers.get('X-Exit-Code'))
```

Output

```text
job 1 exited: code 0, 20.0s
0
```

The request `timeout` is 1 to 30 seconds. When it ends the wait before the job, the reply has `X-Timeout: 1` and exit code 124, and the job keeps running; send the wait again. The CLI retries, so `si job wait` gives up only at its own `--timeout`.

## Stop a job

Kill ends every process of the job, including one that left the session with `setsid`. A job that has ended keeps its code and answers `job N already exited: code N`.

### CLI

```bash
si job start runner -- sleep 3600
si job kill runner 2
```

Output

```text
2
job 2 killed
```

### curl

```bash
curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/job?arg=-q" \
-H "Authorization: Bearer $SI_API_KEY" --data-binary 'sleep 3600'
curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/job?arg=kill&arg=2" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
2
job 2 killed
```

### Python

```python
import os, requests

start = requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/job",
params={"arg": "-q"},
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
data=b"sleep 3600",
)
start.raise_for_status()
number = start.text.strip()
res = requests.post(
f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/job",
params={"arg": ["kill", number]},
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(number)
print(res.text, end="")
```

Output

```text
2
job 2 killed
```

### TypeScript

```ts
const start = await fetch(`https://${process.env.VM!}.slashinfra.dev/usr/bin/job?arg=-q`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
body: 'sleep 3600',
})
if (!start.ok) throw new Error(await start.text())
const number = (await start.text()).trim()

const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/usr/bin/job?arg=kill&arg=${number}`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(await res.text())
console.log(number)
process.stdout.write(await res.text())
```

Output

```text
2
job 2 killed
```

## When to use which

| Use | Choose | What it gives you |
| --- | --- | --- |   
| A program that ends within the timeout | A command | The output and exit code in the reply, in 1 to 30 seconds. | 
| A person at a keyboard | A terminal | An interactive session; closing it ends the program unless it is an `hc` terminal. | 
| Work longer than 30 seconds | A job | A process that outlives the request, a log on disk, and wait and kill. | 
| A program that must stay available | A [service](https://slashinfra.com/docs/platform/services) | A restart after a crash, and a start again after a sleep on disk. |

## Options

| Field | Type | Default | Allowed values | What it changes |
| --- | --- | --- | --- | --- |   
| `path` (path; `si exec -- <PROGRAM>`) | string | Required | An executable file in the VM; a directory answers 405 | The program. A program name goes through `/usr/bin/env` and `PATH`. | 
| `--command` (`-c`) | flag | None | A shell script | Runs the script instead of a program. `si exec` sends it to `/bin/bash -c`; `si job start` sends it as the job’s script. | 
| `arg` (query; after `--`) | array | None | Repeated `arg`, at most 512 KiB together; a NUL byte answers 400 | One argument of the program, in order. | 
| `cwd` (`--cwd`) | string | `/home/user` | An absolute path that exists and that `user` can enter, at most 4096 bytes | The working directory. | 
| `timeout` (`--timeout`) | integer | `30` | 1 to 30 seconds | Ends the process group at the timeout, returns the output so far, and sets `X-Timeout: 1` with exit code 124. | 
| `env` (`--env`) | string | None | `KEY=value`, repeated; the value is split at its first `=` | A variable of this command or job only. The CLI sends it as an `env` query. | 
| `Accept` (header) | string | `text/plain` | `application/json`, `text/event-stream` | JSON splits `stdout` and `stderr` and reports `truncated` and `timed_out`; a stream sends `stdout`, `stderr` and `exit` events. | 
| `program` (path; `si shell --program`) | string | `bash` | `bash`, `zellij`, `tmux`, `herdr` in the CLI; the API also accepts `hc`, `claude`, `codex`, `opencode` | The program of the terminal. | 
| `arg` (query; `si shell`) | array | None | Only for `claude`, `codex` or `opencode`; at most 16 values; a NUL byte answers 400 | The agent’s own options and prompt. | 
| `Upgrade` (header) | string | None | `websocket` | Opens the terminal. Without it, the request returns the terminal page or the program file. | 
| `--follow` (`-f`) | flag | Off | None | Keeps printing new log lines until the job ends. | 
| `--timeout` (`si job wait --timeout`) | integer | None | A positive number of seconds | Gives up after that time with exit code 124; the job keeps running. | 
| `project` (`--project`) | string | `default` | A project name or id | The project of the VM. `SI_PROJECT` applies when the flag is absent. |

## States

| State | What it means for you | What you can do |
| --- | --- | --- |   
| `running` | A process of the job lives. | Read the log, wait, kill. | 
| `exited` | The program ended; `CODE` is its exit code. | Read the log, wait. | 
| `killed` | A signal ended it; `CODE` is 128 + the signal, and 137 for `si job kill` or a sleep on disk. | Read the log. | 
| `oom` | The kernel killed a process for lack of memory; `CODE` is 137. | Read the log; free memory and start again. |

## Errors

| Code | When | Fix |
| --- | --- | --- |   
| [`bad_request`](https://slashinfra.com/docs/reference/errors#bad_request) | A path has a NUL byte, `cwd` is relative or over 4096 bytes, `timeout` is outside 1 to 30, an argument has a NUL byte, or an agent has more than 16 arguments. | Send a valid path, working directory, timeout and arguments. | 
| [`not_found`](https://slashinfra.com/docs/reference/errors#not_found) | The program, working directory or job log does not exist. | Check the path with `si exec runner -- ls -la`. | 
| [`method_not_allowed`](https://slashinfra.com/docs/reference/errors#method_not_allowed) | The path of a command is a directory. | Use an executable file. | 
| [`timeout`](https://slashinfra.com/docs/reference/errors#timeout) | The request body stalled for more than 30 seconds. | Retry with a stable connection. | 
| [`payload_too_large`](https://slashinfra.com/docs/reference/errors#payload_too_large) | Input is over 1 MiB, arguments are over 512 KiB, or an agent terminal’s arguments are over 512 KiB. | Send less; write input to a file and read it inside the VM. | 
| [`too_many_terminals`](https://slashinfra.com/docs/reference/errors#too_many_terminals) | The VM has its 8 terminals open. | Close one terminal. | 
| [`svm_crashed`](https://slashinfra.com/docs/reference/errors#svm_crashed) | The command crashed the VM; its disk returned to the last snapshot. | Check your files, then run the command again. | 
| [`svm_unreachable`](https://slashinfra.com/docs/reference/errors#svm_unreachable) | The node did not answer. | Wait for `Retry-After` and retry. | 
| [`file_read_failed`](https://slashinfra.com/docs/reference/errors#file_read_failed) | The VM could not read the job log. | Retry the read. |

Errors that any request can return are in the [error catalog](https://slashinfra.com/docs/reference/errors).

## Permissions

Every operation on this page goes to the VM’s own host. A key reaches it when it belongs to the VM’s organization and includes the VM’s project; the VM host checks that scope and does not check a key action. A grant reaches only the methods, paths and arguments it names; see [Grants](https://slashinfra.com/docs/platform/grants).

| Operation | Who can | Key action |
| --- | --- | --- |   
| Run a command | Any member with a key that includes the VM’s project | None | 
| Open a terminal | Any member with a key that includes the VM’s project | None | 
| Start a job | Any member with a key that includes the VM’s project | None | 
| List jobs | Any member with a key that includes the VM’s project | None | 
| Read the log | Any member with a key that includes the VM’s project | None | 
| Wait for a job | Any member with a key that includes the VM’s project | None | 
| Stop a job | Any member with a key that includes the VM’s project | None |

## Limits

- A command timeout is 1 to 30 seconds and 30 by default. At the timeout the process group ends with exit code 124. 
- Standard input is 1 MiB. Combined standard output and error is 1 MiB in one reply; the API cuts the rest and sets `X-Truncated: 1`. A stream has no 1 MiB output cap. 
- Arguments are at most 512 KiB together. 
- A VM serves 64 requests at once by default (`concurrency`), and its node accepts 16 by default. A request above the lower limit waits in the queue. See [VMs](https://slashinfra.com/docs/platform/vms). 
- A VM has 8 terminal connections. The ninth answers 429 `too_many_terminals`. 
- The newest 64 jobs are kept. A start removes the oldest ended jobs. A job number never repeats on a VM and survives a sleep.

The full list is in [Limits](https://slashinfra.com/docs/reference/limits).

## Next

- [Background work](https://slashinfra.com/docs/build/background-work): start a job, disconnect, and read its log and exit code. 
- [Services](https://slashinfra.com/docs/platform/services): keep a program running after a crash and a wake. 
- [Sleep and wake](https://slashinfra.com/docs/how/sleep-and-wake): what a job keeps across a sleep.
