Skip to main content
Any port a sandbox 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

uv pip install "nullspace-sdk==0.1.9"
export NULLSPACE_API_KEY=ns_live_...
export NULLSPACE_API_URL=https://api.your-nullspace-domain

Python

preview_example.py
import time
import urllib.request

from nullspace import Sandbox

with Sandbox.create(template="base", timeout=120) as sandbox:
    sandbox.files.write("/workspace/index.html", "hello from a sandbox\n")
    server = sandbox.commands.run(
        "cd /workspace && python3 -m http.server 8080 --bind 0.0.0.0",
        shell=True,
        background=True,
    )
    try:
        url = sandbox.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

outside fetch: hello from a sandbox
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; to put your own domain and auth in front, see Custom preview proxy. Related: Networking overview · Access control