> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bonya.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Build, run, and preview a web app

> Get a small web app running inside a sandbox and reachable at a public preview URL, entirely from the CLI

Get a small web app running inside a sandbox and reachable at a public preview URL — entirely from the `bonya` CLI. Every command below uses the `bonya-dev` template. If you haven't installed the CLI or logged in yet, start with the [Quickstart](https://docs.bonya.ai/quickstart.md).

**1. Create a sandbox**

```shell theme={null}
bonya create web --template bonya-dev
```

**2. Checkpoint before installing anything**

Snapshots here are one-way checkpoints — there's no `restore` or `list` command in the CLI today (see [Snapshots](https://docs.bonya.ai/concepts/snapshots.md)). Treat the id below as an insurance policy you'd manually rebuild from — a fresh sandbox plus reapplying your changes — not a one-command rollback.

```shell theme={null}
bonya snapshot create web
```

**3. Make a workspace directory**

```shell theme={null}
bonya fs mkdir web /workspace/app
```

**4. Upload the app as a tarball**

`fs upload` moves exactly one file's raw bytes per call — there's no directory upload (see [Files](https://docs.bonya.ai/concepts/files.md)). Package the project locally first, then upload the single archive:

```shell theme={null}
tar czf app.tar.gz -C my-app .
bonya fs upload web ./app.tar.gz /workspace/app.tar.gz
```

**5. Extract it on the sandbox**

```shell theme={null}
bonya exec web -- tar xzf /workspace/app.tar.gz -C /workspace/app
```

`tar` prints nothing on success. Confirm the files landed:

```shell theme={null}
bonya fs ls web /workspace/app
```

**6. Check for a language runtime before assuming it's there**

Nothing guarantees a Node runtime is preinstalled on every template (see [Templates](https://docs.bonya.ai/concepts/templates.md)) — check first, and only proceed with `npm install` if it succeeds. `bonya-dev` does include Node:

```shell theme={null}
bonya exec web -- node --version
```

**7. Install dependencies**

```shell theme={null}
bonya exec web --cwd /workspace/app -- npm install
```

**8. Start the dev server in a managed session**

A managed session keeps the process running after your terminal disconnects — unlike `exec`, which ends when the connection does (see [Sessions](https://docs.bonya.ai/concepts/sessions.md)). `session create` has no `--cwd` flag, so `cd` inside the command itself:

```shell theme={null}
bonya session create web dev -- sh -c 'cd /workspace/app && npm run dev'
```

**9. Publish a preview URL**

```shell theme={null}
bonya preview create web 3000 --name app
```

`token` is the default auth mode — the URL alone isn't enough to reach it; see [Previews](https://docs.bonya.ai/concepts/previews.md) for the token exchange. Passing `--auth public` would skip that, at the cost of anyone with the URL being able to reach it.

**10. Watch it running**

```shell theme={null}
bonya session attach web dev
```

Ctrl+D (or Ctrl+C once) detaches your terminal — it does not kill the session, unlike a plain `exec`.

**11. Clean up**

Tear down what this page created, in reverse order:

```shell theme={null}
bonya preview delete web pv-4j25exovxnccyjqpcgpnbpoiue
bonya session kill web dev
bonya snapshot delete web snp-92670f726baeaa8e4fbf926c73150fe8
bonya delete web --force
```

## Next steps

> [card] [Previews](https://docs.bonya.ai/concepts/previews.md)
>
> Auth modes, capability upgrades, and preview limitations.

> [card] [Expose a preview](https://docs.bonya.ai/guides/expose-a-preview.md)
>
> The guide this tutorial's preview step is based on.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.