Sandbox Public URL

Updated at:

sandbox.getHost(port) gets the public host for a specific port in the sandbox. It is useful for previewing web applications, exposing temporary APIs, or connecting to debugging services in the sandbox.

Start a service and get its access URL

const handle = await sandbox.commands.run("python3 -m http.server 8000", {
  background: true,
});

const host = sandbox.getHost(8000);
const url = `https://${host}`;

console.log(url);

await sandbox.commands.kill(handle.pid);

Python example:

handle = sandbox.commands.run(
    "python3 -m http.server 8000",
    background=True,
)

host = sandbox.get_host(8000)
url = f"https://{host}"

print(url)

sandbox.commands.kill(handle.pid)

Recommendations

  • The service must listen on the target port, or the access URL will not respond correctly.

  • For long-running services, use background commands and persist the process pid.

  • The access URL is suitable for temporary service previews, not as a long-term production domain.