Represents an active sandbox for running commands and file operations async.
This class is typically obtained from AsyncSandboxClient.sandbox() and supports the async context manager protocol for automatic cleanup.
AsyncSandbox(
self,
name: str,
template_name: str,
dataplane_url: Optional[str] = None,
id: Optional[str] = None,
status: str = 'ready',
status_message: Optional[str] = None,
created_at: Optional[str] = None,
updated_at: Optional[str] = None,
ttl_seconds: Optional[int] = None,
idle_ttl_seconds: Optional[int] = None,
expires_at: Optional[str] = None,
_client: AsyncSandboxClient = None,
_auto_delete: bool = True
)Example:
async with await client.sandbox(template_name="python-sandbox") as sandbox: result = await sandbox.run("python --version") print(result.stdout)
Create an AsyncSandbox from API response dict.
Execute a command in the sandbox asynchronously.
Reconnect to a running or recently-finished command.
Resumes output from the given byte offsets. Any output produced while the client was disconnected is replayed from the server's ring buffer.
Write content to a file in the sandbox asynchronously.
Read a file from the sandbox asynchronously.
Open a TCP tunnel to a port inside the sandbox.
Creates a local TCP listener that forwards connections through a yamux-multiplexed WebSocket to the specified port inside the sandbox. Works with any TCP protocol (databases, Redis, HTTP, etc.).
Usage::
async with await sandbox.tunnel(remote_port=5432) as t:
conn = await asyncpg.connect(host="127.0.0.1", port=t.local_port)