Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

17.1 KB
Raw Blame

name: boxlite-cloud-apps description: Build a web app on BoxLite Cloud with database, storage, login, deploys, and rollback. Use when the user shares a BoxLite App prompt or asks to build, deploy, or update an App.

Build an app on BoxLite Cloud

The App prompt supplies the organization API URL, App name, and environment. Use the BoxLite platform CLI with an organization credential with Apps permissions.

Use boxlite app for platform operations and stay within the App named in the prompt. Finish when the App is live at its URL and you have verified it.

0. Install and orient (once per session)

Install the BoxLite CLI with curl -fsSL https://sh.boxlite.ai | sh and put $HOME/.local/bin on PATH. Run boxlite app --help to see the available commands.

Use the server URL from the App prompt to sign in with boxlite auth login --url <server-url>. For an organization key, use boxlite auth login --url <server-url> --method api-key and enter the key at the prompt, or provide BOXLITE_REST_URL, BOXLITE_REST_PATH_PREFIX and BOXLITE_API_KEY for automation. Use the server and organization from the handoff.

Use the App: and Environment: values from the prompt. Before using an existing project, check that .boxlite/link.json matches the App and organization API URL.

boxlite auth whoami
BOXLITE_API_URL="<url>" boxlite app status --app "<app>" --env "<env>" --json
BOXLITE_API_URL="<url>" BOXLITE_APP="<app>" boxlite app status --details --env "<env>"

boxlite auth whoami identifies the platform credential. boxlite app status --json reports the selected environment and its URL, all environments, and the App’s available sign-in providers. Use boxlite --version for the installed CLI version. Pass --env <env> when targeting an environment other than the one in the project link.

If boxlite app status --details shows a live deployment, work in the user's existing project or clone the live code into an empty directory with BOXLITE_API_URL="<url>" boxlite app init --clone <app> --env <env>. Enter the cloned App directory and run boxlite app init --pull if the CLI reports newer changes online. Then go to step 3.

Use boxlite app deploy --help for offline deployment options. With --json, document commands write one JSON value to stdout and failures write an error object to stderr. Following logs emits one JSON object per line.

1. Decide what the app needs

Read the user's sentence and decide, before writing code:

If the app… Declare Notes
stores anything that must survive a restart (records, accounts, settings) [database] + migrations/ Postgres. Never install a database inside the app.
stores user-uploaded files or generated files [[volume]] A directory mounted into the app. Never keep uploads on local disk.
has "my", "only me", per-user data, an admin, or anything private keep [auth] (it is on by default) Use the providers boxlite app status --json lists under sign_in_providers. Remove [auth] only for a fully anonymous site. Private access uses Open app in the console or the CLI with an authorized platform session or organization key. Set public when the request says anyone with the URL may open the App. Otherwise ask (§6).
runs something on a timer ("every morning", "daily digest") [[schedule]] Sends POST <path> (header X-BoxLite-Schedule: <name>) to your web service, so the handler must accept POST; it wakes the app.
is only a frontend (no server logic, no database) one [[service]] with static = "dist/" No server needed; the platform serves the files.
receives webhooks (Stripe, GitHub, …) public_paths = ["/webhooks/*"] at the top of boxlite.toml The app stays private; only those paths are open. Check the provider's signature in the handler; never open / or /* this way (that is access = "public", which needs the user's say-so).
needs a third-party API key the user mentioned an App secret plus a [secrets] reference If the user gave you the value: printf %s "$VALUE" | boxlite app vars set STRIPE_SECRET_KEY --secret. Otherwise ask the user for it, and say why. Bind an existing org secret with boxlite app vars set STRIPE_SECRET_KEY --from org/stripe. Never put a secret value in a file, a variable or a command argument.

Who may open the app and what needs signing in are two separate settings; settle both now, not after the deploy:

  • Access (access in boxlite.toml): private (default) and org require platform access. public lets anyone with the URL open the App.
  • Sign-in ([auth], [auth].protect): which pages or actions need an account, once someone can open the app.

For a specific environment, set access in [env.staging] and apply it with boxlite app deploy --config-only --env staging --yes. An online override wins over the manifest. To switch back to the manifest, send {"access":null} to boxlite api PUT "/apps/$APP/envs/$ENV/access" --input -.

If the request means other people will use it (players, customers, a team) and does not say who, ask the user in your first reply which access they want, together with anything else you need from them, so the first deploy already has it. Never set public without their say-so.

Pick the stack you are best at that fits in one directory. Defaults that work well here: Node 22 + a small server (Express/Hono/Fastify) serving a built frontend, or plain server-rendered pages. Python 3.12 works too (image = "python").

2. Initialise the project

mkdir -p <app> && cd <app>
BOXLITE_API_URL="<url>" boxlite app init --app "<app>" --env "<env>"

This command writes the selected App, environment, and organization API URL to .boxlite/link.json. It creates boxlite.toml when missing, updates .gitignore, and keeps a BoxLite block in AGENTS.md.

Edit boxlite.toml. A complete example:

public_paths = ["/webhooks/*"]    # optional, before any [table]: paths anyone may reach even when the app is private (a payment provider's or GitHub's webhook). Verify the provider's signature there.

[app]
name = "crm"

[runtime]
image = "node"                    # node | python | base
size  = "small"                   # nano | small | medium | large
build = ["npm ci", "npm run build"]   # runs in the cloud on every deploy

[[service]]
name    = "web"
command = "node server.js"
port    = 3000                    # the platform sets PORT; this is only a hint
health  = "/healthz"              # must return 2xx when ready

[database]
migrations = "migrations/"        # 0001_init.sql, 0002_….sql — the only way to change tables

[[volume]]
name  = "uploads"
mount = "/data/uploads"

[auth]                            # on by default; delete it for a fully anonymous site. Sign-in only: who may reach the app at all is the access level (private by default)
providers = ["github"]          # only providers `boxlite app status --json` lists under `sign_in_providers` here
protect   = ["/app/*"]            # optional: paths that require login

[[schedule]]
name   = "daily-summary"
cron   = "0 9 * * *"              # UTC
target = "web:/jobs/daily-summary"

[variables]
LOG_LEVEL = "info"

3. Runtime rules your code must follow

These are hard requirements. Most failed deploys break one of them.

  1. Listen on process.env.PORT on 0.0.0.0. Never hardcode the port, never bind 127.0.0.1/localhost.
  2. The app owns its origin. Each environment is served at the root of its own origin (BOXLITE_APP_URL, e.g. https://crm.apps.example.test, no trailing slash), so ordinary root-absolute links (/api/items, /assets/app.js) and any framework's defaults work. Never hardcode or guess that URL: build absolute links (emails, third-party callbacks) from process.env.BOXLITE_APP_URL, and read it for your own checks from boxlite app status --details --json | jq -r .urls.app.
  3. Health endpoint at the health path returning 2xx quickly (no DB call needed). Traffic switches only after it passes.
  4. Exit on SIGTERM within 10 s.
  5. Logs to stdout/stderr. Use boxlite app logs for service output, boxlite app logs --dashboard for visitor requests and boxlite app logs --box for the supervisor buffer.
  6. Persistent data only in the database or a volume path. Local disk is wiped on every deploy and rebuild.
  7. Database: connect with process.env.DATABASE_URL (SSL is in the URL; with pg use new Pool({ connectionString: process.env.DATABASE_URL })). Change tables only by adding a new numbered file in migrations/; never edit an applied migration. boxlite app psql --query "SELECT 1" runs read-only unless you pass --write, and on main it refuses DDL even then.
  8. Login ([auth], on by default): link to /.boxlite/auth/login?next=/app and /.boxlite/auth/logout?next=/ (next is a path inside the app). The platform handles OAuth: the browser briefly leaves your origin for the provider and comes back to next signed in. Never implement callbacks or sessions yourself, and never set cookies whose name starts with bxl_ or that carry a Domain attribute (the platform drops them).
    • Build login buttons for the providers that boxlite app status --json lists under sign_in_providers. To configure this App’s own OAuth client, use the Dashboard’s sign-in methods. Identify signed-in users by ID because providers can withhold email addresses.
    • email (a 6-digit code mailed to the visitor, no OAuth app) sends through the App's own SMTP account. Use it when the user wants email login or has no GitHub/Google users. Ask the user for the account (host, port, username, password, from address), then configure and test the sender in the App’s Authentication tab and add "email" to providers.
    • Signed-in requests carry X-BoxLite-User-Id (uuid), X-BoxLite-User-Email (URI-encoded when it is not plain ASCII), X-BoxLite-User-Name (always URI-encoded) and X-BoxLite-User-Provider; read the email and name with decodeURIComponent. No header = anonymous. The platform strips these from what browsers send, so trust them. Scope every per-user query by the user id.
    • X-BoxLite-User-Role is owner when the visitor manages this App in the BoxLite console (the user who asked you for the app, and their teammates), else user; /.boxlite/auth/me returns it as role. Gate an admin or back-office area on it: never ask the user for their account name, never hardcode an email or id. Test both an owner and a regular visitor in the verification environment.
    • [auth].protect paths need login: a GET that accepts text/html (a browser) is redirected (302) to /.boxlite/auth/login, everything else gets 401 JSON. For other pages decide yourself, and use /.boxlite/auth/me (JSON or 401) from the frontend.
    • Optional: X-BoxLite-Identity is an RS256 JWT (5 min) with the same user, for when you forward identity to another service. Verify its signature against ${BOXLITE_APP_URL}/.boxlite/auth/jwks.json and check that aud equals BOXLITE_APP_URL exactly. Every app's tokens are signed with the same key, so a token with another aud belongs to another app and must be refused.
    • With [database], users also appear in boxlite.users(id, email, name, provider, created_at, last_login_at). For row-level security run SET LOCAL boxlite.user_id = '<id>' in the transaction and write policies with boxlite.current_user_id().
  9. Frontend build output (dist/, build/) is produced in the cloud by [runtime].build; do not commit or rely on uploading it. Commit a lockfile (package-lock.json, uv.lock) so the cloud build matches yours.
  10. Environment variables available at runtime: PORT, BOXLITE_APP_URL, BOXLITE_APP (the App name), BOXLITE_ENV, DATABASE_URL (if [database]), everything in [variables] and [secrets]. Those platform names (DATABASE_URL, PORT, anything starting with BOXLITE_) cannot be [variables] or [secrets] names (check rule reserved_variable). Volumes are plain directories at their mount path.

4. Validate, deploy and diagnose

boxlite app deploy --check
boxlite app deploy --dry-run
boxlite app deploy -m "Publish the reviewed changes"
boxlite app status --json
  • Use boxlite app deploy --config-only --yes to provision declared resources before publishing code. A migration belongs in the next numbered SQL file. Create it with boxlite app psql --migration NAME; verify applied migrations with boxlite api GET "/apps/$APP/envs/$ENV/db/applied".
  • Use boxlite app dev --env qa for a local development service. boxlite app psql --env qa opens a PostgreSQL client and boxlite app psql --proxy --env qa exposes a local PostgreSQL port. Both default to read-only.
  • boxlite app deploy waits for the deployment. Use --verbose for build logs. A stale base means online configuration changed. Run boxlite app init --pull, review boxlite.toml.bak and merge local edits before retrying. Use --force only if the user expressly wants to overwrite the online changes.
  • When a deployment fails, inspect its step and log tail, then boxlite app logs --deployment N. boxlite app status --details --json reports the active release, resource usage, sign-in state and recommended fixes. boxlite app status --services and boxlite app logs --source web --level error --since 10m show service health and recent failures. Roll back with boxlite app rollback N if the user requests a previous release.
  • The first healthy deployment publishes a stable preview URL. To bind a hostname the organization holds, use boxlite domain bind HOST --type app --app NAME --env ENV. The Dashboard handles domain registration and DNS setup.
  • boxlite api POST "/apps/$APP/envs/$ENV/services/all/restart" restarts all services together. boxlite api GET "/apps/$APP/envs/$ENV/probe?path=/health" checks the App through the proxy.
  • Use boxlite app vars list for live configuration and pending local edits. Store an App secret through stdin. To change an environment’s permissions, SMTP sender, OAuth providers or files on a volume, use its Dashboard tab or the organization-scoped REST API.

5. Verify before you report

Use the App and environment from the handoff. Set APP and ENV to their names for the raw API examples. Raw paths are relative to the selected organization. For example, boxlite api GET "/apps/$APP/envs/$ENV/db/schema" reads its database schema. For machine-readable SQL results, use boxlite app psql --query "SELECT 1" --json. Use --query - to read SQL from stdin; --explain returns the query plan.

Exercise features that write data in a separate environment. Use a fresh name and create it without copying production rows. For example, when qa is available:

printf '%s' '{"name":"qa"}' | boxlite api POST "/apps/$APP/envs" --input -
boxlite app deploy --env qa -m "Verify the requested flow"
boxlite app request /healthz --env qa --expect 200
boxlite app psql --env qa --query "SELECT 1" --json

For a private URL, open the selected environment with boxlite app status --env qa --open or Open app in the Dashboard. Use boxlite app request /app --env qa --as [email protected] --expect 200 to check a protected route as a test visitor. Verify the actual user journey in a browser, including sign-in, protected pages, owner access and regular visitor access where relevant. Exercise each requested write and check its result. Use --role owner with a test visitor to exercise owner-only pages, and verify a regular user is refused. Keep the platform credential on the management API.

Delete only the verification environment you created, after testing, with boxlite app delete --app "$APP" --env qa --yes. This deletes the verification data. Publish the verified changes to the target environment and repeat the health and browser checks there.

To retain a decision for the next session, send a JSON object with a short text field to boxlite api POST "/apps/$APP/notes" --input note.json. Notes are visible to other sessions. Keep credentials out of them.

6. Report to the user

One short message:

  • Give the App's permanent URL from boxlite app status --json. Add --env <name> for a test environment. For a private App, tell the user to use Open app in the BoxLite console. Keep credentials and one-time test links out of the handoff.
  • What you built, in their words, and what you verified (list).
  • Ask for decisions the user still needs to make, such as the App's public audience, a third-party key, or a custom domain.

Do not mention internal steps, retries, or platform terms (Spec, Release, Box, tunnel).

Rules

  • Never print, log, commit, or echo BOXLITE_API_KEY, DATABASE_URL, or any secret. Never pass them as command-line arguments. (The CLI masks them in its own output, but your shell commands are yours.)
  • Set access = "public" in boxlite.toml and publish it only when the user wants anyone with the URL to be able to open the App. Otherwise keep it private and ask.
  • Confirm destructive changes with the user, including App deletion, database restore and rollback with --with-database. A raw API mutation takes effect immediately. Only the disposable verification environment you created for this task can be deleted without further confirmation.
  • Stay within the App and organization from the handoff.