A prompt becomes a running page on the user’s VM, at a web address that you send only to that user. The user gets a VM, an agent in it writes the app, and a port link opens the page.
Before you start
Section titled “Before you start”- An approved account and an API key from the API keys page.
- A base VM with Claude Code signed in. Follow steps 1 and 2 of Fix a failing test with Claude Code once, and keep the VM’s id. Each user’s VM starts as a copy of the base VM, so every copy carries the same Claude Code sign-in.
- Python 3.12 with
requests, or Node 22, for the Python and TypeScript tabs.
Set these once in your terminal. The user id has lowercase letters, digits and hyphens, at most 27 characters, as in One VM per user.
export SI_API_KEY=si_...export BASE=<base-vm-id>export USER_ID=adaexport PROMPT='A page with a counter and a reset button.'1. Create the user’s VM
Section titled “1. Create the user’s VM”Create the VM from the base VM. The request is the one from One VM per user, with fork_of added. Send it again for the same user, and it returns the same VM with 200.
curl -sS -X POST "https://api.slashinfra.com/svms" \ -H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \ -d "{\"name\":\"user-$USER_ID\",\"fork_of\":\"$BASE\",\"labels\":{\"user\":\"$USER_ID\"},\"if_absent\":true}"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": f"user-{os.environ['USER_ID']}", "fork_of": os.environ["BASE"], "labels": {"user": os.environ["USER_ID"]}, "if_absent": True, },)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: `user-${process.env.USER_ID!}`, fork_of: process.env.BASE!, labels: { user: process.env.USER_ID! }, if_absent: true, }),})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,"labels":{"user":"ada"},...}Set VM to the id in the reply. The steps below use it.
export VM=6f1c0f0e8a2. Send the prompt
Section titled “2. Send the prompt”Write the prompt to a file in the VM. The agent reads it in the next step.
curl -sS -o /dev/null -w "%{http_code}\n" -X PUT "https://$VM.slashinfra.dev/home/user/prompt.txt" \ -H "Authorization: Bearer $SI_API_KEY" --data-binary "$PROMPT"import os, requests
res = requests.put( f"https://{os.environ['VM']}.slashinfra.dev/home/user/prompt.txt", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, data=os.environ["PROMPT"].encode(),)res.raise_for_status()print(res.status_code)const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/home/user/prompt.txt`, { method: 'PUT', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` }, body: process.env.PROMPT!,})if (!res.ok) throw new Error(`upload failed: ${res.status}`)console.log(res.status)2013. Have the agent write the app
Section titled “3. Have the agent write the app”Start a job that runs the agent, then wait for the job to end. The agent writes index.html in /home/user/app. --permission-mode bypassPermissions lets Claude Code edit files and run commands without asking. A job has no one to answer a prompt, and the agent works inside its own VM. The wait repeats while the reply has X-Timeout: 1, as in Background work.
Keep the two functions from this step in the same file. Step 4 uses start_job.
JOB=$(curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/job?cwd=/home/user&arg=-q" \ -H "Authorization: Bearer $SI_API_KEY" \ --data-binary 'mkdir -p /home/user/app && cd /home/user/app && claude -p --permission-mode bypassPermissions "Build this as one static page in index.html: $(cat /home/user/prompt.txt)"')
while HEADERS=$(curl -sS -D - -o /dev/null -X POST "https://$VM.slashinfra.dev/usr/bin/job?arg=wait&arg=$JOB" \ -H "Authorization: Bearer $SI_API_KEY"); grep -qi '^X-Timeout: 1' <<<"$HEADERS"; do :; donegrep -i '^X-Exit-Code' <<<"$HEADERS" | cut -d' ' -f2 | tr -d '\r'import os, requests
def start_job(script: str, cwd: str) -> str: res = requests.post( f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/job", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, params={"cwd": cwd, "arg": "-q"}, data=script.encode(), ) res.raise_for_status() return res.text.strip()
def wait_for_job(job: str) -> int: while True: res = requests.post( f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/job", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, params=[("arg", "wait"), ("arg", job)], ) res.raise_for_status() if "X-Timeout" not in res.headers: return int(res.headers["X-Exit-Code"])
script = ( "mkdir -p /home/user/app && cd /home/user/app && " 'claude -p --permission-mode bypassPermissions "Build this as one static page in index.html: $(cat /home/user/prompt.txt)"')print(wait_for_job(start_job(script, "/home/user")))const jobUrl = `https://${process.env.VM!}.slashinfra.dev/usr/bin/job`const auth = { Authorization: `Bearer ${process.env.SI_API_KEY!}` }
async function startJob(script: string, cwd: string): Promise<string> { const res = await fetch(`${jobUrl}?cwd=${encodeURIComponent(cwd)}&arg=-q`, { method: 'POST', headers: auth, body: script }) if (!res.ok) throw new Error(`job start failed: ${res.status}`) return (await res.text()).trim()}
async function waitForJob(job: string): Promise<number> { for (;;) { const res = await fetch(`${jobUrl}?arg=wait&arg=${job}`, { method: 'POST', headers: auth }) if (!res.ok) throw new Error(`wait failed: ${res.status}`) if (!res.headers.has('X-Timeout')) return Number(res.headers.get('X-Exit-Code')) }}
const script = 'mkdir -p /home/user/app && cd /home/user/app && claude -p --permission-mode bypassPermissions "Build this as one static page in index.html: $(cat /home/user/prompt.txt)"'console.log(await waitForJob(await startJob(script, '/home/user')))04. Serve the page on port 3000
Section titled “4. Serve the page on port 3000”Start a web server in a job, then open port 3000 to links. The authenticated setting accepts members and link holders. A request without a link gets 401.
curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/job?cwd=/home/user/app&arg=-q" \ -H "Authorization: Bearer $SI_API_KEY" --data-binary 'python3 -m http.server 3000'
curl -sS -X PUT "https://api.slashinfra.com/svms/$VM/ports/3000" \ -H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \ -d '{"access":"authenticated"}'API reference: Run a program
import os, requests
print(start_job("python3 -m http.server 3000", "/home/user/app"))
res = requests.put( f"https://api.slashinfra.com/svms/{os.environ['VM']}/ports/3000", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, json={"access": "authenticated"},)res.raise_for_status()print(res.text)console.log(await startJob('python3 -m http.server 3000', '/home/user/app'))
const res = await fetch(`https://api.slashinfra.com/svms/${process.env.VM!}/ports/3000`, { method: 'PUT', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ access: 'authenticated' }),})if (!res.ok) throw new Error(`port failed: ${res.status}`)console.log(await res.text())4{"access":"authenticated","port":3000,...}5. Make the user’s link
Section titled “5. Make the user’s link”Make a link that lasts one day, and send it only to this user. Anyone who holds the link can open the page. The product does not tie a link to one viewer.
curl -sS -X POST "https://api.slashinfra.com/svms/$VM/ports/3000/url" \ -H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \ -d '{"ttl_s":86400}'API reference: Control API operation
import os, requests
res = requests.post( f"https://api.slashinfra.com/svms/{os.environ['VM']}/ports/3000/url", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, json={"ttl_s": 86400},)res.raise_for_status()print(res.text)const res = await fetch(`https://api.slashinfra.com/svms/${process.env.VM!}/ports/3000/url`, { method: 'POST', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ ttl_s: 86400 }),})if (!res.ok) throw new Error(`link failed: ${res.status}`)console.log(await res.text()){"url":"https://3000-6f1c0f0e8a.slashinfra.dev/?si_access=...","expires_at":...}Check it works
Section titled “Check it works”Open the url in a browser. You should see the page that the agent wrote. The same address without the si_access query gets 401.
If it doesn’t work
Section titled “If it doesn’t work”| Symptom | Cause | Fix |
|---|---|---|
Step 3 prints a code other than 0 |
The agent stopped, or it is not signed in. | Read /var/log/jobs/<job>.log in the VM, then run step 3 again. |
401 in the browser |
The link expired. | Make a new link in step 5. |
503 with nothing listens on port 3000 |
The web server job ended. | Run step 4 again. |
Scroll horizontally to see all columns.
Clean up
Section titled “Clean up”curl -sS -o /dev/null -w "%{http_code}\n" -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']}"},)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!}` },})console.log(res.status)204- One VM per user: the create-or-reuse request and the cleanup of idle users.
- Share and embed: put the running page inside your own site.
- Background work: the jobs this guide starts and waits for.