PortsService
Section titled “PortsService”class PortsService()Synchronous PortsService.
PortsService.__init__
Section titled “PortsService.__init__”def __init__(impl: AsyncPortsService, bridge: SyncBridge) -> NonePortsService.expire_signed_preview_link
Section titled “PortsService.expire_signed_preview_link”def expire_signed_preview_link(port: int, token: str) -> NoneRevoke a signed preview link before its natural expiry.
PortsService.expose
Section titled “PortsService.expose”def expose(port: int, *, public: bool = False) -> PreviewEndpointRegister a sandbox port as a preview endpoint.
PortsService.is_in_use
Section titled “PortsService.is_in_use”def is_in_use(port: int) -> boolPortsService.iter_endpoints
Section titled “PortsService.iter_endpoints”def iter_endpoints(*, cursor: Optional[str] = None, limit: Optional[int] = None) -> Iterator[PreviewEndpoint]PortsService.list
Section titled “PortsService.list”def list() -> ListResult[int]PortsService.list_endpoints
Section titled “PortsService.list_endpoints”def list_endpoints(*, cursor: Optional[str] = None, limit: Optional[int] = None) -> ListResult[PreviewEndpoint]PortsService.preview_link
Section titled “PortsService.preview_link”def preview_link(port: int) -> PreviewLinkPreview URL plus access token for one in-VM port.
PortsService.set_public
Section titled “PortsService.set_public”def set_public(port: int, *, public: bool) -> PreviewEndpointChange the visibility of an exposed port.
PortsService.signed_preview_link
Section titled “PortsService.signed_preview_link”def signed_preview_link(port: int, *, expires_in_seconds: Optional[int] = None) -> SignedPreviewLinkReturn a self-contained signed URL for one in-VM port.
PortsService.unexpose
Section titled “PortsService.unexpose”def unexpose(port: int) -> NoneAsyncPortsService
Section titled “AsyncPortsService”class AsyncPortsService()AsyncPortsService.__init__
Section titled “AsyncPortsService.__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) -> NoneAsyncPortsService.list
Section titled “AsyncPortsService.list”async def list() -> ListResult[int]AsyncPortsService.is_in_use
Section titled “AsyncPortsService.is_in_use”async def is_in_use(port: int) -> boolAsyncPortsService.list_endpoints
Section titled “AsyncPortsService.list_endpoints”async def list_endpoints(*, cursor: Optional[str] = None, limit: Optional[int] = None) -> ListResult[PreviewEndpoint]AsyncPortsService.iter_endpoints
Section titled “AsyncPortsService.iter_endpoints”async def iter_endpoints(*, cursor: Optional[str] = None, limit: Optional[int] = None) -> AsyncIterator[PreviewEndpoint]AsyncPortsService.expose
Section titled “AsyncPortsService.expose”async def expose(port: int, *, public: bool = False) -> PreviewEndpointRegister 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.
AsyncPortsService.set_public
Section titled “AsyncPortsService.set_public”async def set_public(port: int, *, public: bool) -> PreviewEndpointChange 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.
AsyncPortsService.preview_link
Section titled “AsyncPortsService.preview_link”async def preview_link(port: int) -> PreviewLinkPreview 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.
AsyncPortsService.signed_preview_link
Section titled “AsyncPortsService.signed_preview_link”async def signed_preview_link(port: int, *, expires_in_seconds: Optional[int] = None) -> SignedPreviewLinkReturn 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.”AsyncPortsService.expire_signed_preview_link
Section titled “AsyncPortsService.expire_signed_preview_link”async def expire_signed_preview_link(port: int, token: str) -> NoneRevoke 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.
AsyncPortsService.unexpose
Section titled “AsyncPortsService.unexpose”async def unexpose(port: int) -> NonePortMapping
Section titled “PortMapping”@dataclass(frozen=True)class PortMapping()Attributes:
portintprotostr = ‘tcp’