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

# Port Forwarding

> Start a web server in a machine and fetch it from outside via a signed preview URL.

Any port a machine process binds on `0.0.0.0` can be exposed through a signed
preview URL. This example serves a file with Python's built-in HTTP server and
fetches it from your machine.

## Setup

```bash theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
uv pip install "nullspace-sdk==1.0.0"
export NULLSPACE_API_KEY=ns_live_...
export NULLSPACE_API_URL=https://api.your-nullspace-domain
```

## Python

```python preview_example.py theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
import time
import urllib.request

from nullspace import Machine

with Machine.create(template="base", timeout=120) as machine:
    machine.files.write("/workspace/index.html", "hello from a machine\n")
    server = machine.commands.run(
        "cd /workspace && python3 -m http.server 8080 --bind 0.0.0.0",
        shell=True,
        background=True,
    )
    try:
        url = machine.get_url(8080)
        time.sleep(1)  # give the server a moment to bind
        body = urllib.request.urlopen(url, timeout=10).read().decode()
        print("outside fetch:", body.strip())
    finally:
        server.kill()
```

## Expected output

```text theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
outside fetch: hello from a machine
```

The URL embeds a signed `edge_token` — treat it as a secret and don't log it.
For longer-lived links, expiry control, and revocation, see
[Preview URLs](../networking/preview-urls); to put your own domain and auth in
front, see [Custom preview proxy](../networking/custom-preview-proxy).

Related: [Networking overview](../networking/overview) ·
[Access control](../networking/access-control)
