On this page

Agent builds an app

~10 min Python TypeScript

Goal: Wire an LLM agent to MIOSA so it can write code, build it inside a sandbox, open a live preview, then publish to a production deployment — all from a single user prompt.

What you’ll use: Sandboxes, Previews, Deployments

What you’ll build

A function build_and_deploy(prompt) that hands a prompt to an LLM, streams generated code into a sandbox, runs npm run build, surfaces a preview URL, then publishes an immutable production release. The user sees a live URL in under 60 seconds.

The pattern is the same whether you use Anthropic, OpenAI, or any other model — MIOSA is the execution layer, your agent loop is the thinking layer.

Prerequisites

  • A MIOSA workspace API key (msk_live_*) — see API Keys
  • An Anthropic API key (or substitute your preferred provider)
  • Node 22+ or Python 3.11+

Step 1 — Install and configure

Step 2 — Boot a sandbox

Create a Next.js sandbox. The template already has Node, pnpm, and a Next.js scaffold — no npx create-next-app needed.

Step 3 — Ask the LLM to generate code

Call the model with a system prompt that instructs it to produce a complete app/page.tsx file. Keep it deterministic by setting temperature=0.

Step 4 — Write the file and build

Write the generated code into the sandbox filesystem, install any new dependencies, and run the build. Stream exec output so you can surface progress to the user in real time.

Step 5 — Open a preview

Start the Next.js dev server, then expose port 3000 as a public URL your user can open immediately.

Step 6 — Publish to production

When the user confirms, publish the sandbox to a permanent production deployment. The deployment is immutable — the sandbox can be destroyed after this.

Full script

What you learned

  • Sandboxes boot in ~150 ms from a warm template — fast enough to create one per user request.
  • The LLM and the sandbox are completely decoupled. Swap any model without touching the execution logic.
  • A single self-correction turn catches most build errors automatically.
  • deployments.publish produces an immutable release; the sandbox can be destroyed immediately after.
  • background: true on exec keeps long-running processes alive without blocking your driver script.

Next

Was this helpful?