Files and programs over HTTP
You write a file to your VM, run a program over HTTP, and read the program’s exit code. Each step is one request.
Before you start
Section titled “Before you start”- An approved account. New accounts need approval first; the dashboard shows your status.
- An API key from the API keys page. The dashboard shows the secret once, so copy it when it appears.
- Python 3.12 with
requests, or Node 22, for the Python and TypeScript tabs. The curl tab needs only curl.
1. Create a VM
Section titled “1. Create a VM”The first request to a VM starts it, so the create request is the only setup.
export SI_API_KEY=si_...curl -sS -X POST "https://api.slashinfra.com/svms" \ -H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \ -d '{"name":"files-example"}'API reference: Control API operation
import os, requests
res = requests.post( "https://api.slashinfra.com/svms", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, json={"name": "files-example"},)res.raise_for_status()print(res.json()["id"])const res = await fetch('https://api.slashinfra.com/svms', { method: 'POST', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ name: 'files-example' }),})if (!res.ok) throw new Error(`create failed: ${res.status}`)const svm = (await res.json()) as { id: string }console.log(svm.id){"id":"6f1c0f0e8a","generation":1,...}Set VM to the id in the reply. The examples below use it.
export VM=6f1c0f0e8a2. Write a file
Section titled “2. Write a file”Send the file as the body of a PUT. The parent directory must exist. A new file has mode 0644, so it is not executable.
curl -sS -X PUT "https://$VM.slashinfra.dev/home/user/report.py" \ -H "Authorization: Bearer $SI_API_KEY" --data-binary @- <<'PY'import sysmonth = sys.stdin.read().strip()print(f"report written for {month}")PYimport os, requests
PROGRAM = """import sysmonth = sys.stdin.read().strip()print(f"report written for {month}")"""res = requests.put( f"https://{os.environ['VM']}.slashinfra.dev/home/user/report.py", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, data=PROGRAM.encode(),)res.raise_for_status()print(res.status_code)const program = `import sysmonth = sys.stdin.read().strip()print(f"report written for {month}")`const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/home/user/report.py`, { method: 'PUT', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` }, body: program,})if (!res.ok) throw new Error(`upload failed: ${res.status}`)console.log(res.status)The reply is 201 for a new file and 204 for a replaced one. The body is empty.
3. Run a program
Section titled “3. Run a program”POST the program’s input as the body. The path picks the executable. /usr/bin/env finds python3 in the PATH, so the file does not need the executable bit. Arguments go in the query, one arg each.
curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/env?arg=python3&arg=/home/user/report.py" \ -H "Authorization: Bearer $SI_API_KEY" --data-binary '2026-11'import os, requests
res = requests.post( f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/env", params=[("arg", "python3"), ("arg", "/home/user/report.py")], headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, data=b"2026-11",)res.raise_for_status()print(res.text, end="")const url = new URL(`https://${process.env.VM!}.slashinfra.dev/usr/bin/env`)url.searchParams.append('arg', 'python3')url.searchParams.append('arg', '/home/user/report.py')const res = await fetch(url, { method: 'POST', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` }, body: '2026-11',})if (!res.ok) throw new Error(`run failed: ${res.status}`)process.stdout.write(await res.text())report written for 2026-11Each request starts a new process as user in /home/user. A cd or export in one request does not carry into the next. Keep state in files.
4. Read the exit code
Section titled “4. Read the exit code”A 200 means the request reached the VM. It does not mean the program succeeded. The program’s exit code is in the X-Exit-Code header.
curl -sS -i -X POST "https://$VM.slashinfra.dev/usr/bin/env?arg=python3&arg=/home/user/report.py" \ -H "Authorization: Bearer $SI_API_KEY" --data-binary '2026-11'import os, requests
res = requests.post( f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/env", params=[("arg", "python3"), ("arg", "/home/user/report.py")], headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, data=b"2026-11",)print(res.status_code, res.headers["X-Exit-Code"])const url = new URL(`https://${process.env.VM!}.slashinfra.dev/usr/bin/env`)url.searchParams.append('arg', 'python3')url.searchParams.append('arg', '/home/user/report.py')const res = await fetch(url, { method: 'POST', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` }, body: '2026-11',})console.log(res.status, res.headers.get('X-Exit-Code'))HTTP/2 200X-Exit-Code: 0...5. Stream output
Section titled “5. Stream output”For output that takes a while, ask for an event stream with Accept: text/event-stream. The stream sends one stdout or stderr event for each chunk. It ends with one exit event that carries the code. A stream keeps the VM awake while it runs.
curl -sSN -X POST "https://$VM.slashinfra.dev/usr/bin/env?arg=python3&arg=/home/user/report.py" \ -H "Authorization: Bearer $SI_API_KEY" -H "Accept: text/event-stream" --data-binary '2026-12'import os, requests
with requests.post( f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/env", params=[("arg", "python3"), ("arg", "/home/user/report.py")], headers={ "Authorization": f"Bearer {os.environ['SI_API_KEY']}", "Accept": "text/event-stream", }, data=b"2026-12", stream=True,) as res: res.raise_for_status() for line in res.iter_lines(decode_unicode=True): if line: print(line)const url = new URL(`https://${process.env.VM!}.slashinfra.dev/usr/bin/env`)url.searchParams.append('arg', 'python3')url.searchParams.append('arg', '/home/user/report.py')const res = await fetch(url, { method: 'POST', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}`, Accept: 'text/event-stream', }, body: '2026-12',})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 }))}event: stdoutdata: "report written for 2026-12\n"
event: exitdata: {"code":0,"timed_out":false}Check it works
Section titled “Check it works”You should now see report written for 2026-11 in the reply to step 3. The header in step 4 reads X-Exit-Code: 0. The stream in step 5 ends with an exit event whose code is 0.
If it doesn’t work
Section titled “If it doesn’t work”| Symptom | Cause | Fix |
|---|---|---|
401 unauthorized |
The key is missing, wrong or deleted. | Set SI_API_KEY to a key from the API keys page. |
404 not_found on any request |
The VM id is wrong, or the VM is deleted. | Check VM against the id from step 1. |
X-Exit-Code is not 0 with status 200 |
The program failed. The reply still has 200. |
Read the output of that request, fix the program and upload it again. |
Scroll horizontally to see all columns.
Clean up
Section titled “Clean up”curl -sS -i -X DELETE "https://api.slashinfra.com/svms/$VM" \ -H "Authorization: Bearer $SI_API_KEY"API reference: Control API operation
import os, requests
res = requests.delete( f"https://api.slashinfra.com/svms/{os.environ['VM']}", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},)res.raise_for_status()print(res.status_code)const res = await fetch(`https://api.slashinfra.com/svms/${process.env.VM!}`, { method: 'DELETE', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },})if (!res.ok) throw new Error(`delete failed: ${res.status}`)console.log(res.status)HTTP/2 204- Give an agent a shell: run these requests from an agent loop that keeps its files between calls.
- Background work: run a command that takes longer than one request.
- Sleep and wake: what the VM keeps while it sleeps between requests.
- Files: every file operation, header and limit.