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

# Public URLs and ports

> Every sandbox has its own HTTPS address. Serve an app, an API or a preview from it, share the link, and let it sleep: the next visitor wakes it with the app still running.

Every sandbox has **its own HTTPS address**, which you find in its `url` field. If a program inside the sandbox
listens on the sandbox's **exposed port**, anyone can reach that program at the address, from anywhere, over a
secure connection with a valid certificate. You do not need to set up a server, a domain or a certificate yourself.

This is useful in many situations:

* **Show a user the app their agent just built**, live, while the agent keeps working on it.
* **Share a preview** of a branch with a teammate or a reviewer.
* **Receive webhooks** from services such as GitHub, Stripe or Slack in a sandbox you are testing.
* **Run a small API or bot** without deploying it anywhere.

And because a sandbox sleeps when nobody uses it, **a preview that nobody is looking at costs nothing for compute**. When the
next visitor arrives, the sandbox wakes up and the app is still running.

## Serve an app

This example serves a small web app with one page and one JSON endpoint. It only uses Node, which is already
installed, and listens on port 3000. Follow the steps to get it running at a public address.

**1. Start a sandbox that serves port 3000**

```bash title="CLI" run theme={null}
SBX=$(fibre create --port 3000 --idle-timeout 1m --lifetime 20m --label docs=public-url --json | jq -r .id)
fibre url "$SBX"   # https://sbx-….fibre.run
```

```typescript title="TypeScript" run theme={null}
import { Sandbox } from "@fibre-dev/sdk";

const sbx = await Sandbox.create({
  exposedPort: 3000,
  idleTimeout: 60,
  lifetime: 1200,
  labels: { docs: "public-url" },
});
console.log(sbx.url); // https://sbx-….fibre.run
```

```python title="Python" run theme={null}
from fibre import Sandbox

sbx = Sandbox.create(exposed_port=3000, idle_timeout=60, lifetime=1200, labels={"docs": "public-url"})
print(sbx.url)  # https://sbx-….fibre.run
```

```bash title="curl" run capture=SBX=.id theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"exposed_port": 3000, "idle_timeout_sec": 60, "lifetime_sec": 1200, "labels": {"docs": "public-url"}}'
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "id": "…",
>   "status": "running",
>   "hostname": "…",
>   "url": "…"
> }
> ```

**2. Put the app in**

```bash title="CLI" run theme={null}
fibre exec "$SBX" -i -- sh -c 'mkdir -p /app && cat > /app/server.js' <<'JS'
const http = require("http");
const started = new Date().toISOString();
let visits = 0;

http.createServer((req, res) => {
  if (req.url === "/api/status") {
    res.writeHead(200, { "content-type": "application/json" });
    return res.end(JSON.stringify({ ok: true, started, visits }));
  }
  visits++;
  res.writeHead(200, { "content-type": "text/html" });
  res.end("<h1>Hello from a fibre sandbox</h1><p>Visit #" + visits + "</p>");
}).listen(3000);
JS
```

```typescript title="TypeScript" run theme={null}
await sbx.files.write("/app/server.js", `
const http = require("http");
const started = new Date().toISOString();
let visits = 0;

http.createServer((req, res) => {
  if (req.url === "/api/status") {
    res.writeHead(200, { "content-type": "application/json" });
    return res.end(JSON.stringify({ ok: true, started, visits }));
  }
  visits++;
  res.writeHead(200, { "content-type": "text/html" });
  res.end("<h1>Hello from a fibre sandbox</h1><p>Visit #" + visits + "</p>");
}).listen(3000);
`);
```

```python title="Python" run theme={null}
sbx.files.write("/app/server.js", """
const http = require("http");
const started = new Date().toISOString();
let visits = 0;

http.createServer((req, res) => {
  if (req.url === "/api/status") {
    res.writeHead(200, { "content-type": "application/json" });
    return res.end(JSON.stringify({ ok: true, started, visits }));
  }
  visits++;
  res.writeHead(200, { "content-type": "text/html" });
  res.end("<h1>Hello from a fibre sandbox</h1><p>Visit #" + visits + "</p>");
}).listen(3000);
""")
```

```bash title="curl" run theme={null}
cat <<'EOF' | curl -sS -o /dev/null -X PUT "$FIBRE_API_URL/v1/sandboxes/$SBX/files/content?path=/app/server.js" \
  -H "Authorization: Bearer $FIBRE_API_KEY" --data-binary @-
const http = require("http");
const started = new Date().toISOString();
let visits = 0;

http.createServer((req, res) => {
  if (req.url === "/api/status") {
    res.writeHead(200, { "content-type": "application/json" });
    return res.end(JSON.stringify({ ok: true, started, visits }));
  }
  visits++;
  res.writeHead(200, { "content-type": "text/html" });
  res.end("<h1>Hello from a fibre sandbox</h1><p>Visit #" + visits + "</p>");
}).listen(3000);
EOF
```

**3. Start the server so it keeps running**

`keep: true` makes the server a program that keeps running on its own, even across sleep and wake. The second
line waits until the server answers before moving on.

```bash title="CLI" run theme={null}
fibre exec "$SBX" --detach --keep -- node /app/server.js
fibre exec "$SBX" --timeout 60 -- 'until curl -sf -o /dev/null localhost:3000/api/status; do sleep 1; done'
```

```typescript title="TypeScript" run theme={null}
await sbx.spawn(["node", "/app/server.js"], { keep: true });
await sbx.run("until curl -sf -o /dev/null localhost:3000/api/status; do sleep 1; done", { timeout: 60 });
```

```python title="Python" run theme={null}
sbx.spawn(["node", "/app/server.js"], keep=True)
sbx.run("until curl -sf -o /dev/null localhost:3000/api/status; do sleep 1; done", timeout=60)
```

```bash title="curl" run theme={null}
curl -sS -o /dev/null -X POST "$FIBRE_API_URL/v1/sandboxes/$SBX/commands" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"command": ["node", "/app/server.js"], "keep": true}'

curl -sS -o /dev/null -X POST "$FIBRE_API_URL/v1/sandboxes/$SBX/exec" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"command": ["sh", "-c", "until curl -sf -o /dev/null localhost:3000/api/status; do sleep 1; done"]}'
```

**4. Open it from anywhere**

```bash title="CLI" run theme={null}
URL=$(fibre url "$SBX")
curl -sS "$URL/"; echo         # <h1>Hello from a fibre sandbox</h1><p>Visit #1</p>
curl -sS "$URL/api/status"     # {"ok":true,"started":"2026-…","visits":1}
```

```typescript title="TypeScript" run theme={null}
const page = await fetch(sbx.url).then((r) => r.text());
console.log(page); // <h1>Hello from a fibre sandbox</h1><p>Visit #1</p>

const status = await fetch(`${sbx.url}/api/status`).then((r) => r.json());
console.log(status); // { ok: true, started: '2026-…', visits: 1 }
```

```python title="Python" run theme={null}
import json
from urllib.request import urlopen

page = urlopen(sbx.url).read().decode()
print(page)  # <h1>Hello from a fibre sandbox</h1><p>Visit #1</p>

status = json.load(urlopen(f"{sbx.url}/api/status"))
print(status)  # {'ok': True, 'started': '2026-…', 'visits': 1}
```

```bash title="curl" run theme={null}
URL=$(curl -sS "$FIBRE_API_URL/v1/sandboxes/$SBX" -H "Authorization: Bearer $FIBRE_API_KEY" | jq -r .url)
curl -sS "$URL/"
echo
curl -sS "$URL/api/status"
```

> [accordion] Output
>
> ```text title="output" expected theme={null}
> Hello from a fibre sandbox
> ```

**Paste the `url` into your browser, or send it to someone.** They see the app, over HTTPS, without setting
anything up.

## A visitor wakes it

This sandbox was created to sleep after one quiet minute. Wait for it to fall asleep, then **simply visit the URL
again**. You do not need to call the API or wake the sandbox first. The first request waits a moment while the
sandbox wakes up, then gets its answer from the same server, which still remembers its earlier visits.

```bash title="CLI" run theme={null}
until [ "$(fibre get "$SBX" --json | jq -r .status)" = standby ]; do sleep 5; done
echo "asleep, costing nothing; now a visitor arrives:"
curl -sS "$URL/api/status"     # the same "started", visits 1: the same server, woken
```

```typescript title="TypeScript" run theme={null}
while ((await sbx.refresh()).status !== "standby") await new Promise((r) => setTimeout(r, 5000));
console.log(sbx.status); // standby: costing nothing

const afterSleep = await fetch(`${sbx.url}/api/status`).then((r) => r.json());
console.log(afterSleep.started === status.started, afterSleep.visits); // true 1
```

```python title="Python" run theme={null}
import time

while sbx.refresh().status != "standby":
    time.sleep(5)
print(sbx.status)  # standby: costing nothing

after_sleep = json.load(urlopen(f"{sbx.url}/api/status"))
print(after_sleep["started"] == status["started"], after_sleep["visits"])  # True 1
```

```bash title="curl" run theme={null}
for i in $(seq 1 40); do
  [ "$(curl -sS "$FIBRE_API_URL/v1/sandboxes/$SBX" -H "Authorization: Bearer $FIBRE_API_KEY" | jq -r .status)" = standby ] && break
  sleep 5
done
echo "asleep; now a visitor arrives:"
URL=$(curl -sS "$FIBRE_API_URL/v1/sandboxes/$SBX" -H "Authorization: Bearer $FIBRE_API_KEY" | jq -r .url)
curl -sS "$URL/api/status"
```

> [accordion] Output
>
> ```text title="output" expected theme={null}
> "ok":true
> ```

**The `started` time is the same as before the sleep.** That shows the server was resumed, not restarted. Anything
it held in memory, such as user sessions, caches or a loaded model, is still there.

## Live connections

The address carries more than ordinary page loads:

* **WebSockets work**, so features such as live reload, chat and terminals in the browser all work.
* **Streaming responses**, such as server-sent events, reach the visitor as your app writes them.
* **An open connection keeps the sandbox awake.** A user watching a live page is never cut off because the
  sandbox went to sleep.

## Who can open it

> [!WARNING]
>
> **The `url` is public.** Anyone who has the address can open the app, without a Fibre key. The address is long and
> hard to guess, but treat it like a shared link: add your own sign-in to anything private, and never serve secrets
> from it.

If you do not want a sandbox reachable from the internet, simply do not run anything on its exposed port. When
nothing is listening there, the address answers with an error and reaches nothing inside the sandbox.

## Good to know

These details answer the questions that usually come up:

| | |
| - | - |
| The address | `https://<sandbox-id>--<your-org>.fibre.run`, fixed for the sandbox's life, in `url` and `hostname` |
| The port | One per sandbox: `exposed_port` (8000 unless you set it), chosen at create |
| Listen on | Any address in the sandbox; `0.0.0.0` is the safe choice for frameworks that ask |
| HTTPS | Always, with a valid certificate; your app speaks plain HTTP inside |
| Sleeping sandbox | The first request wakes it and waits; requests arriving together share one wake |
| Ready | With your own `image` or `entrypoint`, the create call answers once the port answers |

> [!TIP]
>
> **Development servers** such as Vite, Next.js and webpack often listen only on `localhost` and reject requests for
> unknown hostnames. Start them with `--host 0.0.0.0`, and add the sandbox's hostname to the framework's list of
> allowed hosts if it has one (for Vite, `server.allowedHosts`). [Preview environments](https://docs.fibre.dev/use-cases/dev-server.md) shows
> a complete example.

## Clean up

```bash title="CLI" run theme={null}
fibre delete "$SBX"
```

```typescript title="TypeScript" run theme={null}
await sbx.delete();
```

```python title="Python" run theme={null}
sbx.delete()
```

```bash title="curl" run theme={null}
curl -sS -X DELETE "$FIBRE_API_URL/v1/sandboxes/$SBX" -H "Authorization: Bearer $FIBRE_API_KEY"
```

## Related

> [card] [Preview environments](https://docs.fibre.dev/use-cases/dev-server.md)
>
> A preview per pull request, from a repo.

> [card] [Sleep and wake](https://docs.fibre.dev/sandboxes/sleep-and-wake.md)
>
> What a sleeping app keeps, and what wakes it.

> [card] [Run commands](https://docs.fibre.dev/sandboxes/running-commands.md)
>
> Keep servers running with `keep`.

> [card] [Browser](https://docs.fibre.dev/connect/browser.md)
>
> Test the app with a real browser in the same sandbox.


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