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-tokenheader. Others get403. - Public: anyone with the URL. Set it at create.
Python · TypeScript · CLI
sbx = Sandbox.create("base", network={"allow_public_traffic": True})
const sbx = await Sandbox.create('base', { network: { allowPublicTraffic: true } })
$ fdtn create base -d --publicDo 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)
import { Sandbox } from '@fdtn/sdk' const sbx = await Sandbox.create('base', { timeoutMs: 1_800_000, // 30 minutes network: { allowPublicTraffic: true }, }) await sbx.files.write('/home/user/site/index.html', '<h1>Hello</h1>') const server = await sbx.commands.run('python3 -m http.server 8000 --bind 0.0.0.0', { cwd: '/home/user/site', background: true, timeoutMs: 0, }) const url = `https://${sbx.getHost(8000)}` console.log(url)
$ fdtn create base -d --public --timeout 1800 --name web $ fdtn exec -b -c /tmp @web python3 -m http.server 8000 --bind 0.0.0.0 # open https://8000-<sandbox-id>.sbx.fdtn.dev
2Wait for the server
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,
)await sbx.commands.run( 'for i in $(seq 1 30); do curl -sf http://localhost:8000 >/dev/null && exit 0; sleep 1; done; exit 1', { timeoutMs: 40_000 }, )
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.devon port 443.