https:// link to open and share. This guide is the pattern end to end: one instance per user, a public port for the site, and a small publish endpoint in your app that decides when a port goes public.
site-builder: this guide as a working app
Everything on this page, runnable: create agents from a table, chat with starter prompts, and watch the agent hand back a live URL. Express plus vanilla JS, no build step. Clone it, add your key,
npm start.Your server publishes, not the agent
An agent cannot give itself a public URL: there is no agent-facing route for it, by design, so a prompt-injected agent can never expose a port on its own. Publishing is a Hosting API call with yoursk_live_ key, and that key lives only on your server. The flow that keeps everyone honest:
- At create, your server plants a publish token on the instance.
- The agent, briefed by your app, asks your server to publish, presenting the token.
- Your server verifies the token, applies its own policy, and creates the public port.
1
Create the instance with a publish token
Two fields on
POST /v1/instances carry the token: env puts the raw token in the container, where the agent’s shell can read it, and metadata stores its SHA-256. env is write-only on the API and metadata is readable, so later your server can verify a presented token against the instance it claims to come from without keeping any state.env is set once at create and cannot change, so rotating a token means a new instance; the metadata hash, not the raw token, is what your server reads back later. The budget.credit_micros grants managed-LLM headroom so the agent can work from the first message (see Budgets).2
Brief the agent
The gateway has no system-prompt field on Two variables do the addressing for you:
POST /v1/responses, so app context rides as a preamble your server prepends to the first turn of each session. The brief tells the agent where to build, how to serve, and how to publish:the brief, prepended server-side
SITE_PUBLISH_TOKEN is the one you planted, and AGENT37_INSTANCE_ID is set by the platform in every container, so the agent always knows which instance it is. Any unreserved port works; this guide fixes 8788 so the brief, the endpoint, and your UI all point at the same place.3
Verify and publish in your endpoint
When the agent calls, your server checks the token against the instance’s metadata hash, then creates the public port. Treat The URL comes back once and never changes: with no
409 public_port_exists as success and return the existing URL, so republishing is idempotent:node
prefix it is a random 20-character slug like https://a1b2c3d4e5f6a7b8c9d0.agent37.app, or pass prefix for a deterministic {prefix}-{instanceId} hostname. The agent must reach this endpoint over the internet, so in local dev give your server a public URL first (cloudflared tunnel --url http://localhost:3000).4
Keep the site up
The published URL routes to the port; whatever serves that port must survive the instance’s lifecycle. Two habits from the brief cover it:
- Files under
~. The home directory is the instance’s persistent disk: it survives restarts, image updates, and recovery. Site edits in a later chat turn show up on the live URL with no republish. - Start command in
~/.agent37/hooks/post-restart.sh. The platform runs this hook on every boot of the instance, so the server comes back after a restart or an update. Commands in it must run in the background (nohup ... &); a foreground command stalls the boot.
auto_sleep off (the default) for a site that should be up around the clock. An auto-sleep instance does wake when the URL is visited, but its awake minutes bill at 4x the compute rate, so steady traffic on a public URL makes sleep the wrong trade.Serve it on your own domain
Register a custom domain once and every public-port URL is mirrored under it, still credential-free:https://a1b2c3d4e5f6a7b8c9d0.your-domain.com. Each entry’s domain_urls field lists the mirrored URLs, ready to hand to the user instead of the agent37.app form.
Worth knowing
- Public means public. Anyone with the URL reaches the port, and a request wakes a sleeping instance, which bills compute. Delete the entry (
DELETE /v1/instances/{id}/public-ports/{port}) when a site should go away; see rules and limits for the full list. - One URL per port and at most 20 public ports per instance, so one instance can host several sites on different ports.
- The path
/healthis answered by the platform edge and never reaches the site. - Chat, streaming, and sessions are the standard chat app wiring; this guide only adds the publish flow on top.