Skip to content
View as Markdown
class PortsService()

Synchronous PortsService.

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

Revoke a signed preview link before its natural expiry.

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

Register a sandbox port as a preview endpoint.

def is_in_use(port: int) -> bool
def iter_endpoints(*,
cursor: Optional[str] = None,
limit: Optional[int] = None) -> Iterator[PreviewEndpoint]
def list() -> ListResult[int]
def list_endpoints(*,
cursor: Optional[str] = None,
limit: Optional[int] = None) -> ListResult[PreviewEndpoint]
def preview_link(port: int) -> PreviewLink

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

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

Change the visibility of an 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.

def unexpose(port: int) -> None
class AsyncPortsService()
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
async def list() -> ListResult[int]
async def is_in_use(port: int) -> bool
async def list_endpoints(*,
cursor: Optional[str] = None,
limit: Optional[int] = None) -> ListResult[PreviewEndpoint]
async def iter_endpoints(*,
cursor: Optional[str] = None,
limit: Optional[int] = None) -> AsyncIterator[PreviewEndpoint]
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.v2.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.v2.types.PreviewEndpoint with the URL.

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

Change the visibility of an exposed port.

The request replaces the port’s preview registration in full, so a port that is not exposed yet is exposed with this visibility rather than rejected. 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.v2.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.v2.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.v2.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.

Section titled “Hand link.url to a browser or another tool — no headers needed.”
Section titled “AsyncPortsService.expire_signed_preview_link”
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.v2.types.SignedPreviewLink.

async def unexpose(port: int) -> None
@dataclass(frozen=True)
class PortMapping()

Attributes:

  • port int
  • proto str = ‘tcp’