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

# Preview an HTTP or WebSocket service

> Start a web service inside a Computer, open a private preview, verify it, and close the access when finished.

Private Preview gives you a runtime URL for an HTTP or WebSocket service inside a Running Computer. The service can listen on `127.0.0.1`; you do not need to bind it to every interface.

The URL itself is an access credential. “Private” means it is intended for your authorized development workflow, not that every visitor must independently sign in. Anyone holding the valid URL can access the exposed web service. Keep it private and use an explicit [Share link](https://docs.deepest.dev/network/share.md) when anonymous distribution is intended.

## Start a service

In the Computer's terminal, use a directory containing only the example's public files:

```bash theme={null}
mkdir -p /root/deepest-preview-example
printf 'Deepest preview is working\n' > /root/deepest-preview-example/index.html
python3 -m http.server 3000 --bind 127.0.0.1 --directory /root/deepest-preview-example
```

Keep that shell running. The Developer Image includes Python 3. If using another image, verify prerequisites instead of assuming they exist.

In another shell inside the same Computer:

```bash theme={null}
curl --fail --max-time 5 http://127.0.0.1:3000/
```

Expect `Deepest preview is working`. A Preview URL cannot make a missing application listener appear. For a service inside Docker, [publish its container port to the Computer](https://docs.deepest.dev/environment/docker-and-dev-containers.md) first.

For a background development session you intentionally manage, a terminal multiplexer such as `tmux` can keep the process separate from your interactive connection. Stop that process when the example is finished; it is not a platform deployment service.

## Open the Preview

In the Console, select the Computer, open **Apps**, enter `3000` in **Port**, and choose **Open preview**.

An Agent can use the same public operation:

```js theme={null}
import { Deepest } from "@deepest/sdk";

const { DEEPEST_API_URL, DEEPEST_API_KEY, COMPUTER_ID } = process.env;
if (!DEEPEST_API_URL || !DEEPEST_API_KEY || !COMPUTER_ID) {
  throw new Error("Set the control API URL, Agent Key, and Computer ID.");
}
const deepest = new Deepest({ baseUrl: DEEPEST_API_URL, apiKey: DEEPEST_API_KEY });
const computer = deepest.computer(COMPUTER_ID);
const reply = await computer.preview.open({ port: 3000 });
if (!reply.ok) {
  console.error(reply.error.code, reply.retry, reply.resource_id);
  process.exit(1);
}
// Show only to the intended user, not a public log.
console.log(reply.result.private_url);
```

See [TypeScript SDK](https://docs.deepest.dev/api-and-sdk/typescript.md) for installation and setup. The response identifies the Computer and port with `private_url`. Use that returned URL rather than constructing a hostname.

Opening the same Computer/port again reuses its current Preview URL while that Preview remains valid. Opening Preview checks that the port is reachable; it does not create, start, deploy, or health-monitor your application.

## Verify HTTP and WebSocket behavior

Open the returned URL in your browser, or supply it to a trusted local shell:

```bash theme={null}
curl --fail --show-error --max-time 10 "$PRIVATE_PREVIEW_URL"
```

Expect HTTP success and your example's exact text. Check paths, assets, redirects and application behavior, not only the landing page.

Preview forwards HTTP paths, queries, methods, and bodies and supports WebSocket upgrades with bidirectional traffic.

> [!NOTE]
>
> **Node.js version note:** The self-contained verification probe below uses Node.js's built-in `WebSocket` global, which requires **Node.js 22+** locally. The `@deepest/sdk` client itself supports **Node.js 18+**.

If your own application offers an echo WebSocket at `/ws`, this **local Node.js 22+** probe verifies a real message round trip:

```js theme={null}
const url = new URL("/ws", process.env.PRIVATE_PREVIEW_URL);
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
const ws = new WebSocket(url);
const timer = setTimeout(() => {
  console.error("No expected WebSocket reply");
  ws.close();
  process.exitCode = 1;
}, 10000);
ws.addEventListener("open", () => ws.send("deepest-echo-check"));
ws.addEventListener("message", (event) => {
  if (String(event.data) === "deepest-echo-check") {
    clearTimeout(timer);
    console.log("WebSocket round trip verified");
    ws.close();
  }
});
ws.addEventListener("error", () => {
  clearTimeout(timer);
  console.error("WebSocket connection failed");
  process.exitCode = 1;
});
```

The Python static server above is HTTP-only; it does not create `/ws`. Use your application's actual WebSocket path and protocol. A successful HTTP GET is not proof that a WebSocket session works.

Preview preserves Guest application cookies and application Authorization headers. Those are separate from Deepest's control credentials. Platform login cookies and Account API Keys must not be sent to runtime pages.

## Lifetime and cleanup

```js theme={null}
const closed = await computer.preview.close({ port: 3000 });
if (!closed.ok) {
  console.error(closed.error.code, closed.retry, closed.resource_id);
  process.exit(1);
}
console.log(closed.result.closed);
```

After closing, a new request to the old URL should be rejected. Reopening produces a new valid URL; the old one remains invalid. Closing is idempotent: `closed: false` can mean no current Preview existed.

Closing Preview stops new access through that link. It does not stop the application or the Computer, and it does not promise to terminate every already-established WebSocket connection. Stop the example web server separately when finished.

| Event | Result |
| - | - |
| Stop Computer | Preview cannot serve it and does not automatically Start it |
| Start original Computer | Restart the app if necessary; an existing still-valid Preview can work again |
| Close Preview | Old URL stops accepting new requests |
| Platform restart | Temporary Preview URL may become invalid; reopen through the API/Console |
| Delete Computer | The underlying service and disk are removed under the delete contract |

Preview is not a stable production URL, a custom-domain feature, or arbitrary TCP/UDP exposure. Private Preview is available for Computers, not Sandboxes. Use only the documented Computer Preview operations. Platform-managed control endpoints cannot be exposed through ordinary Preview.

## Diagnose a failed preview

| Symptom | Check and recovery |
| - | - |
| `PREVIEW_UNAVAILABLE` | Verify the listener inside the Computer, the port, and Docker mapping if applicable |
| `NOT_RUNNING` | Explicitly Start the Computer and its service |
| `INVALID_REQUEST` | Use an integer user-service port; managed control endpoints are excluded |
| `ENTITLEMENT_REQUIRED` | Restore Account running access |
| Browser refuses the old link | Reopen Preview and use the returned runtime URL |
| Root page works but assets/WS fail | Inspect actual paths, application origin/host settings and WebSocket route |
| Rate/body rejection | Respect deployment limits and retry guidance; reduce request pressure |
| `UNKNOWN` | Check the original Computer and existing service; do not restart or recreate them blindly |

Preview traffic and application work still consume resources. Runtime link creation is not an extra Computer, and closing the link alone does not release running RAM. See [Account resources](https://docs.deepest.dev/concepts/account-resources.md) and [Network behavior](https://docs.deepest.dev/network/outbound-and-bandwidth.md).

The exact OpenAPI contract remains in the Preview section of the [API reference](https://docs.deepest.dev/api-reference.md). For deliberate external delivery, continue with [Share](https://docs.deepest.dev/network/share.md).


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