https://<port>-<sandbox id>.styne.ai.
Run a web server and open a port
1
Start the server
Run it as a detached command, so the call returns while the server keeps running. The example writes a page and serves
its folder with Python’s built-in server on port 3000. Bind to all interfaces, not only to
detached: true answers 202 as soon as the process runs.127.0.0.1: Python’s server and most frameworks do by default, vite and
next dev need --host 0.0.0.0.2
Check it from inside
stdout, the page: hello-from-a-sandbox.3
Open the port
A sandbox serves its ports privately: every port needs the sandbox’s traffic access token until you expose it as public
(a sandbox created from an E2B SDK, or with Open that URL in a browser or In the E2B SDKs
network.allowPublicTraffic: true, opens all its ports instead):curl it; no token is needed. With "public": false (the default) the port of a
token-gated sandbox is listed and still answers only with the token, which the create answer carries as trafficAccessToken:sbx.get_host(3000) (sbx.getHost(3000)) returns the host part, 3000-<id>.styne.ai.4
Close it and clean up
The same from the SDKs
Port rules
A port a server listens on inside a sandbox is reachable athttps://<port>-<sandbox id>.<domain>. A sandbox serves its
ports privately: every port needs the sandbox’s traffic access token (header e2b-traffic-access-token, or the ?token=
query for wss://) unless you make it public. A sandbox created from an E2B SDK serves its ports publicly, as E2B does,
and so does one created with network.allowPublicTraffic: true; a sandbox made through the Daytona API is private unless
it sets public. You can expose a port on purpose, make it public, and close it again, on any sandbox.
Exposing answers {"port":3000,"public":true,"url":"https://3000-<id>.<domain>"}; the list (GET /sandboxes/{id}/ports)
is an array of those.
publicdefaults tofalse: the port is listed with its URL and still needs the token. Sendtrueto open it to anyone with the URL. Send the same port again to change the flag.DELETEcloses the port: it is listed as private and needs the token, also on a sandbox made with public traffic. It answers204also for a port that was not exposed.49983, the sandbox daemon’s port, cannot be exposed. A sandbox exposes at most 32 ports. A browser session’s ports always need the token.- The list holds the ports you exposed here, not every port a process listens on.
urlis absent on a deployment that serves no sandbox domain. - A sandbox created with
network.allowPublicTrafficopens all its ports until you set a port’s flag orDELETEit: the choice you make for a port wins over the sandbox’s setting. - A change reaches the edge within about 5 seconds, so a port made private may still answer without a token for that long.
- The choice belongs to the running sandbox and ends with it. It is stored, so an API restart keeps it and every API
instance shows the same ports within 5 seconds. Until a restarted instance has loaded the table, every port on it is
token-gated. When the store cannot be reached, a change is refused with
503and nothing changes. - A sandbox of another account is a
404, the same as one that does not exist. - The URL works while the sandbox runs. A sandbox that is paused does not serve; it wakes when you resume it, and the
process is where it was. A killed or unknown sandbox answers
404to everyone, with or without a token. - Long-running servers need a long
timeout(up to 86,400 seconds) or a refresh: see Timeouts, pause and resume. - Websocket upgrades work on the same URL; send the token as
?token=for a private port.