Public URLs
Get the address of a port#
import { Sandbox } from 'e2b'
const sandbox = await Sandbox.create()
const host = sandbox.getHost(3000) // a port is always required
console.log(`https://${host}`) // https://3000-i62mff4ahtrdfdkyn2esc.e2b.appfrom e2b import Sandbox
sandbox = Sandbox.create()
host = sandbox.get_host(3000) # a port is always required
print(f'https://{host}') # https://3000-i62mff4ahtrdfdkyn2esc.e2b.appServe something and fetch it#
const server = await sandbox.commands.run('python -m http.server 3000', { background: true })
const url = `https://${sandbox.getHost(3000)}`
const response = await fetch(url)
console.log(await response.text())
await server.kill()import requests
server = sandbox.commands.run("python -m http.server 3000", background=True)
url = f"https://{sandbox.get_host(3000)}"
print(requests.get(url).text)
server.kill()Options#
Mask the Host header
Some dev servers only answer to localhost. Set maskRequestHost / mask_request_host; ${PORT} is replaced with the real port.
const sandbox = await Sandbox.create({
network: { maskRequestHost: 'localhost:${PORT}' },
})Ports that serve HTTPS themselves
Declare them in httpsPorts / https_ports. The E2B proxy terminates HTTPS at the edge and re-encrypts to the sandbox, so restrictions and host masking still apply.
const sandbox = await Sandbox.create({
network: { httpsPorts: [8443] },
})Keep a URL private
Public access can be restricted per sandbox — see Control internet access and E2B's guide on restricting public access.