Skip to content

AsyncPtyClient

Source: leap0/_async/pty.py

AsyncPtyClient(transport: AsyncTransport)

Create and connect to PTY sessions asynchronously.

Attributes: None.

async list(sandbox: SandboxRef) -> list[PtySession]

List PTY sessions for a sandbox.

Args: sandbox: Sandbox ID or object.

Returns: object: Result returned by this operation.

async create(sandbox: SandboxRef, *, session_id: str | None = None, cols: int | None = None, rows: int | None = None, cwd: str | None = None, envs: dict[str, str] | None = None, lazy_start: bool | None = None, http_timeout: float | None = None) -> PtySession

Create a terminal session with a shell process.

Args: sandbox: Sandbox ID or object. session_id: Session ID. Auto-generated if omitted. cols: Terminal columns. rows: Terminal rows. cwd: Starting directory. envs: Environment variables. lazy_start: Defer shell start until the first WebSocket connection. http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: PtySession: Metadata for the created PTY session.

async get(sandbox: SandboxRef, session_id: str) -> PtySession

Get an object by ID or identifier.

Args: sandbox: Sandbox ID or object. session_id: PTY session identifier.

Returns: object: Result returned by this operation.

async delete(sandbox: SandboxRef, session_id: str, http_timeout: float | None = None) -> None

Kill the shell process and remove the session.

Args: sandbox: Sandbox ID or object. session_id: PTY session identifier. http_timeout: Optional HTTP request timeout in seconds for this SDK call.

async resize(sandbox: SandboxRef, session_id: str, *, cols: int, rows: int) -> PtySession

Resize a PTY session.

Args: sandbox: Sandbox ID or object. session_id: PTY session identifier. cols: Parameter for this operation. rows: Parameter for this operation.

Returns: object: Result returned by this operation.

websocket_url(sandbox: SandboxRef, session_id: str) -> str

Build a websocket URL for this sandbox.

Args: sandbox: Sandbox ID or object. session_id: PTY session identifier.

Returns: object: Result returned by this operation.

async connect(sandbox: SandboxRef, session_id: str, open_timeout: float | None = None, http_timeout: float | None = None, **kwargs: Any) -> AsyncPtyConnection

Open a WebSocket connection for interactive terminal I/O.

Important: Callers are responsible for closing the returned connection, ideally with try/finally or an async context manager wrapper.

Args: sandbox: Sandbox ID or object. session_id: PTY session identifier. open_timeout: Optional WebSocket open timeout in seconds. http_timeout: Deprecated alias for open_timeout. **kwargs: Additional keyword arguments passed to websockets.asyncio.client.connect.

Returns: AsyncPtyConnection: Open WebSocket-backed PTY connection.