Skip to content

Build an app builder

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.

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

Terminal window
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.'

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.

Terminal window
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}"
Output
{"id":"6f1c0f0e8a","generation":1,"labels":{"user":"ada"},...}

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

Terminal window
export VM=6f1c0f0e8a

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

Terminal window
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"
Output
201

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.

Terminal window
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'
Output
0

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.

Terminal window
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"}'
Output
4
Output
{"access":"authenticated","port":3000,...}

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.

Terminal window
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}'
Output
{"url":"https://3000-6f1c0f0e8a.slashinfra.dev/?si_access=...","expires_at":...}

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.

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.

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