Foundational Compute

Ports and URLs

Each port of a sandbox has its own HTTPS address, private by default.

The URL of a port

https://<port>-<sandbox-id>.sbx.fdtn.dev

sbx.get_host(8000) / sbx.getHost(8000) returns the host name without https://. HTTP and WebSocket work. Serve plain HTTP; TLS ends at our edge.

Private and public ports

  • Private (default): only requests with the e2b-traffic-access-token header. Others get 403.
  • Public: anyone with the URL. Set it at create.

Python · TypeScript · CLI

sbx = Sandbox.create("base", network={"allow_public_traffic": True})

Do not serve secrets from a public port.

Read the token from sbx.traffic_access_token / sbx.trafficAccessToken.

$ curl https://8000-<sandbox-id>.sbx.fdtn.dev/ -H "e2b-traffic-access-token: $TOKEN"

1Start a server

Run it in the background with timeout 0, listening on 0.0.0.0.

Python · TypeScript · CLI

serve.py
from fdtn import Sandbox

sbx = Sandbox.create(
    "base",
    timeout=1800,                               # 30 minutes
    network={"allow_public_traffic": True},
)
sbx.files.write("/home/user/site/index.html", "<h1>Hello</h1>")
server = sbx.commands.run(
    "python3 -m http.server 8000 --bind 0.0.0.0",
    cwd="/home/user/site",
    background=True,
    timeout=0,
)
url = f"https://{sbx.get_host(8000)}"
print(url)

2Wait for the server

Python · TypeScript

sbx.commands.run(
    "for i in $(seq 1 30); do curl -sf http://localhost:8000 >/dev/null && exit 0; sleep 1; done; exit 1",
    timeout=40,
)

If the server does not answer in 30 seconds, the SDK raises an error. Then open the URL.

To stop only the server, call server.kill() or fdtn process kill <id> <pid>.

Rules

  • The URL works only while the sandbox runs.
  • Port 49983 is reserved for the sandbox agent.
  • Firewalls must allow *.sbx.fdtn.dev on port 443.

Next