Skip to content
Wardcase Docs

Port exposure

Exposing a port gives it a public HTTPS URL:

https://<port>-<id-part>.wardcase.com

id-part is the sandbox id without its sbx_ prefix, because underscores are not allowed in hostnames. Port 8000 of sbx_4f9k2m8q1z7x3c5v is served at https://8000-4f9k2m8q1z7x3c5v.wardcase.com.

Start a server that listens on 0.0.0.0, then expose its port:

// Start a server that listens on all interfaces, then expose its port.
await sbx.run("nohup python -m http.server 8000 --bind 0.0.0.0 > /tmp/http.log 2>&1 &");
const { url } = await sbx.expose(8000, { access: "public" });
console.log(url); // https://8000-4f9k2m8q1z7x3c5v.wardcase.com
// Token access (the default) returns the token once.
const { url: privateUrl, token } = await sbx.expose(8080);
await sbx.unexpose(8080);

Or with the API:

Terminal window
curl https://api.wardcase.com/v1/sandboxes/sbx_4f9k2m8q1z7x3c5v/ports \
-H "Authorization: Bearer $VIVARIUM_API_KEY" \
-H "Content-Type: application/json" \
-d '{"port":8000,"access":"public"}'

A server that listens only on 127.0.0.1 inside the sandbox cannot be reached this way. Bind it to 0.0.0.0. Requests to a port where nothing is listening get a 502 response.

access is public or token, and the default is token.

  • public: anyone with the URL can reach the port.
  • token: the create response carries a token, once. We store only its hash. Open the URL once with the token as the token query parameter, for example https://8000-4f9k2m8q1z7x3c5v.wardcase.com/?token=<token>. The edge then sets a cookie named vv_exp_<exposure_id> that holds the token, and requires that cookie on every later request. Browsers keep it on their own; for scripts, keep a cookie jar, for example with curl -c jar -b jar.

Requests go to Cloudflare, which checks the exposure and forwards them through a tunnel to the sandbox’s host. The host passes them to the sandbox’s port. WebSocket connections pass through too.

Each exposed port is a first-level subdomain of wardcase.com, so Cloudflare Universal SSL covers it with a valid certificate.

In production the exposure domain should be a separate registered domain, so content served from a sandbox never shares an origin or cookies with the dashboard or the API.

GET /v1/sandboxes/{id}/ports lists a sandbox’s exposed ports. DELETE /v1/sandboxes/{id}/ports/{port} removes one. Exposures end when the sandbox is destroyed.

port.exposed and port.unexposed for each change, with the URL and the access mode. Requests to the port are not recorded: the catalogue defines a sampled port.request event, but the edge does not emit it.