Sign Up

PortsService

class PortsService()

PortsService.__init__

def __init__(transport: Optional[AsyncTransport],
             api: Optional[AsyncTransport] = None,
             *,
             sandbox_id: Optional[str] = None,
             mint_preview_token: Optional[Callable[[int], Awaitable[Optional[SandboxAccessToken]]]] = None) -> None

PortsService.list

async def list() -> ListResult[int]

PortsService.is_in_use

async def is_in_use(port: int) -> bool

PortsService.list_endpoints

async def list_endpoints() -> ListResult[PreviewEndpoint]

PortsService.expose

async def expose(port: int, *, public: bool = False) -> PreviewEndpoint

Register a sandbox port as a preview endpoint.

If the port is already exposed, returns the existing endpoint (updating its visibility if public differs from the current value). Public endpoints need no credential. Programmatic access to a private one needs the token from preview_link (see daytona.types.PreviewLink) or a signed_preview_link URL; a browser can also sign in when the deployment has preview login.

:param port: TCP port inside the sandbox (1–65535). :param public: When True the endpoint is publicly accessible without any credential. :returns: daytona.types.PreviewEndpoint with the URL.

PortsService.set_public

async def set_public(port: int, *, public: bool) -> PreviewEndpoint

Change the visibility of an already-exposed port.

Raises a 404 error when the port has not been exposed yet — call expose first. Public endpoints need no credential. Programmatic access to a private one needs the token from preview_link or a signed_preview_link URL; a browser can also sign in when the deployment has preview login.

:param port: TCP port inside the sandbox. :param public: True to make the endpoint publicly accessible; False to restrict it to credentialed callers. :returns: Updated daytona.types.PreviewEndpoint.

async def preview_link(port: int) -> PreviewLink

Preview URL plus access token for one in-VM port.

Callers send the token in the X-Daytona-Preview-Token header; a minted sandbox token (a JWT) is also accepted as a Bearer or ?rlp_token=, but the route's HMAC fallback token works ONLY in the header. Public endpoints need no token (token == ""). The returned daytona.types.PreviewLink also carries expires_at when the token's expiry is known. For private endpoints, a client that can mint (a project key, no caller-supplied token) gets a short-lived sandbox access token scoped to exactly this port (PLAN-SANDBOX-TOKEN-JWT D9), unless the preview-url route already returned a sandbox JWT; otherwise the route token is passed through unchanged.

async def signed_preview_link(port: int,
                              *,
                              expires_in_seconds: Optional[int] = None) -> SignedPreviewLink

Return a self-contained signed URL for one in-VM port.

The token is embedded in the hostname, so no extra headers or credentials are needed — the right choice for handing a URL to a browser, a tool, or any client that cannot set request headers.

The default lifetime is 60 seconds. Pass a longer expires_in_seconds for multi-step use (the deployment caps the maximum, typically 7 days). Revoke the link early with expire_signed_preview_link.

:param port: TCP port inside the sandbox (1–65535). :param expires_in_seconds: Requested token lifetime in seconds (positive integer). Omit for the server default (60 s). :returns: daytona.types.SignedPreviewLink with url, token, and expires_at.

Example::

link = await sandbox.ports.signed_preview_link(8080, expires_in_seconds=300)

Hand link.url to a browser or another tool — no headers needed.

async def expire_signed_preview_link(port: int, token: str) -> None

Revoke a signed preview link before its natural expiry.

:param port: TCP port the link was issued for. :param token: The token field from daytona.types.SignedPreviewLink.

PortsService.unexpose

async def unexpose(port: int) -> None

PortRequest

@dataclass(frozen=True)
class PortRequest()

Attributes:

  • vm_port int
  • proto str = 'tcp'

SyncPortsService

class SyncPortsService()

Synchronous PortsService.

SyncPortsService.__init__

def __init__(impl: PortsService, bridge: SyncBridge) -> None
def expire_signed_preview_link(port: int, token: str) -> None

Revoke a signed preview link before its natural expiry.

SyncPortsService.expose

def expose(port: int, *, public: bool = False) -> PreviewEndpoint

Register a sandbox port as a preview endpoint.

SyncPortsService.is_in_use

def is_in_use(port: int) -> bool

SyncPortsService.list

def list() -> ListResult[int]

SyncPortsService.list_endpoints

def list_endpoints() -> ListResult[PreviewEndpoint]
def preview_link(port: int) -> PreviewLink

Preview URL plus access token for one in-VM port.

SyncPortsService.set_public

def set_public(port: int, *, public: bool) -> PreviewEndpoint

Change the visibility of an already-exposed port.

def signed_preview_link(port: int,
                        *,
                        expires_in_seconds: Optional[int] = None) -> SignedPreviewLink

Return a self-contained signed URL for one in-VM port.

SyncPortsService.unexpose

def unexpose(port: int) -> None