# Build an app builder

Turn a prompt into a running page that one user opens: a VM per user, an agent that writes the app and a port link.

Source: https://slashinfra.com/docs/build/app-builder
Last modified: 2026-11-30T16:36:19.000Z

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

- An approved [account](https://app.slashinfra.com/) and an API key from the [API keys](https://app.slashinfra.com/keys) page. 
- A base VM with Claude Code signed in. Follow steps 1 and 2 of [Fix a failing test with Claude Code](https://slashinfra.com/docs/agents/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](https://slashinfra.com/docs/build/one-vm-per-user).

```bash
export SI_API_KEY=si_...
export BASE=<base-vm-id>
export USER_ID=ada
export PROMPT='A page with a counter and a reset button.'
```

## 1. Create the user’s VM

Create the VM from the base VM. The request is the one from [One VM per user](https://slashinfra.com/docs/build/one-vm-per-user), with `fork_of` added. Send it again for the same user, and it returns the same VM with `200`.

### curl

```bash
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}"
```

### Python

```python
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"])
```

### TypeScript

```ts
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)
```

Output

```text
{"id":"6f1c0f0e8a","generation":1,"labels":{"user":"ada"},...}
```

Set `VM` to the `id` in the reply. The steps below use it.

```bash
export VM=6f1c0f0e8a
```

## 2. Send the prompt

Write the prompt to a file in the VM. The agent reads it in the next step.

### curl

```bash
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"
```

### Python

```python
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)
```

### TypeScript

```ts
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)
```

Output

```text
201
```

## 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](https://slashinfra.com/docs/build/background-work).

Keep the two functions from this step in the same file. Step 4 uses `start_job`.

### curl

```bash
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 :; done
grep -i '^X-Exit-Code' <<<"$HEADERS" | cut -d' ' -f2 | tr -d '\r'
```

### Python

```python
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")))
```

### TypeScript

```ts
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')))
```

Output

```text
0
```

## 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

```bash
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"}'
```

### Python

```python
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)
```

### TypeScript

```ts
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())
```

Output

```text
4
```

Output

```text
{"access":"authenticated","port":3000,...}
```

## 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

```bash
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}'
```

### Python

```python
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)
```

### TypeScript

```ts
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())
```

Output

```text
{"url":"https://3000-6f1c0f0e8a.slashinfra.dev/?si_access=...","expires_at":...}
```

## 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

| 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. |

## Clean up

> Caution
> 
> 
> 
> Deletes the user’s VM and its files. Copy any file you want to keep first. The user’s next request creates a new VM from the base VM, with none of the old files.

### curl

```bash
curl -sS -o /dev/null -w "%{http_code}\n" -X DELETE "https://api.slashinfra.com/svms/$VM" \
-H "Authorization: Bearer $SI_API_KEY"
```

### Python

```python
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)
```

### TypeScript

```ts
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)
```

Output

```text
204
```

## Next

- [One VM per user](https://slashinfra.com/docs/build/one-vm-per-user): the create-or-reuse request and the cleanup of idle users. 
- [Share and embed](https://slashinfra.com/docs/build/share-and-embed): put the running page inside your own site. 
- [Background work](https://slashinfra.com/docs/build/background-work): the jobs this guide starts and waits for.
