# How to build an agent that turns a prompt into a live web app preview

Build a filterable directory from a prompt, serve it from a sandbox, and revise it at the same HTTPS URL.

Canonical URL: https://getfloo.com/blog/build-an-agent-that-previews-a-web-app

## TL;DR

Ask for a directory of three bookshops, open it in a browser, then ask the agent to add a fourth. The second version appears at the same preview URL.

- Use a small app with one visible interaction: filtering a directory.
- Turn the model's structured response into HTML and serve a single directory.
- Keep the process alive during review and close the preview when you're done.

## Start with an app you can exercise in ten seconds

Ask for three bookshops in an imaginary seaside town. A visitor should be able to type a word and narrow the list. That interaction gives you a better acceptance check than “the agent produced HTML.” The example supports a directory, its entries, and revisions to them. A shopping cart or a sign-in flow would need its own data model and behavior.

The model chooses the title and entries. A short Python renderer escapes each string and adds a search input. Its event handler compares the query with the visible text of each entry. That division lets you change the brief in plain language while keeping the behavior small enough to inspect. [Preview agent source](https://getfloo.com/examples/sandbox-agents/preview_agent.py) · [Host helper](https://getfloo.com/examples/sandbox-agents/agent_tools.py)

## Start the preview

Use Python 3.10 or later, a signed-in Claude Code CLI, and a floo account with sandbox credits. Sign in with the floo CLI or set FLOO_API_KEY in your shell. Run these commands in an empty directory.

```bash
python3 -m venv .venv
. .venv/bin/activate
python -m pip install floo-sandbox==0.2.0
export FLOO_API_KEY="${FLOO_API_KEY:-$(floo auth token)}"
base=https://getfloo.com/examples/sandbox-agents
curl -fsSLO "$base/agent_tools.py"
curl -fsSLO "$base/preview_agent.py"
python preview_agent.py
```

At the first prompt, enter `Build a directory of three bookstores in an imaginary seaside town.` Leave the terminal open. The sandbox expires ten minutes after creation, including time spent at the prompts. Run the script again for a fresh review session. Visit the HTTPS URL it prints, choose a distinctive word from one listing, and enter it in the filter. Clear the input to bring back the full directory.

## Give the browser a stable address

The sandbox exposes port 8000 over HTTPS. Python serves only the directory containing the rendered page. That detail keeps the rest of the workspace outside the document root.

```python
box.filesystem.write_text(page, "/work/site/index.html")
server = box.exec("python3", "-m", "http.server", "8000", "--bind", "0.0.0.0",
                  "--directory", "/work/site")
url = box.tunnels()[8000].url
```

A preview needs a running listener as well as a file. If your version returns a 502, check that the server is alive, binds to the port you exposed, and listens on all interfaces inside the sandbox. Anyone with this example's URL can open it. Use invented listings for the demo. [Sandbox port and access behavior](https://getfloo.com/docs/guides/sandboxes#open-a-port-to-the-internet)

## Change one thing and verify the old work survives

At the second prompt, enter `Keep the existing shops, add Compass Books, and change the title to Gullhaven weekend bookshops.` The host supplies the prior directory to the model, validates the new entries, and overwrites the same HTML file. The server and its tunnel keep running.

In our run the first page had three listings. A second request to the same HTTPS URL returned the new title, the three original stores, and Compass Books. Refresh your browser and search for Compass. That verifies two different things: the requested edit reached the server, and the existing filter still works on the revised data.

Press Enter at the final prompt to terminate the sandbox. This URL belongs to a temporary review session. For an app people will bookmark, take the reviewed source through your normal deployment flow. [App deployment guide](https://getfloo.com/docs/deploy/customer-app)
