Devbox¶
The AsyncDevbox class provides asynchronous methods for managing and interacting with a devbox instance.
Asynchronous devbox resource class.
- class runloop_api_client.sdk.async_devbox.AsyncDevbox(client, devbox_id)[source]¶
High-level async interface for managing a Runloop devbox.
This class provides a Pythonic, awaitable API for interacting with devboxes, including command execution, file operations, networking, and lifecycle management.
Example
>>> devbox = await sdk.devbox.create(name="my-devbox") >>> async with devbox: ... result = await devbox.cmd.exec(command="echo 'hello'") ... print(await result.stdout()) # Devbox is automatically shut down on exit
- async get_info(**options)[source]¶
Retrieve current devbox status and metadata.
- Parameters:
options (
Unpack[BaseRequestOptions]) – Optional request configuration- Returns:
Current devbox state info
- Return type:
- async await_running(*, polling_config=None)[source]¶
Wait for the devbox to reach running state.
- Parameters:
polling_config (PollingConfig | None, optional) – Optional polling behavior overrides, defaults to None
- Returns:
Devbox state info after it reaches running status
- Return type:
- async await_suspended(*, polling_config=None)[source]¶
Wait for the devbox to reach suspended state.
- Parameters:
polling_config (PollingConfig | None, optional) – Optional polling behavior overrides, defaults to None
- Returns:
Devbox state info after it reaches suspended status
- Return type:
- async shutdown(**options)[source]¶
Shutdown the devbox, terminating all processes and releasing resources.
- Parameters:
options (
Unpack[LongRequestOptions]) – Optional long-running request configuration- Returns:
Final devbox state info
- Return type:
- async suspend(**options)[source]¶
Suspend the devbox without destroying state.
Returns immediately after issuing the suspend request. Call
await_suspended()if you need to wait for the devbox to reach thesuspendedstate (contrast with the synchronous SDK, which blocks).- Parameters:
options (
Unpack[LongRequestOptions]) – Optional long-running request configuration- Returns:
Suspended devbox state info
- Return type:
- async resume(**options)[source]¶
Resume a suspended devbox.
Returns immediately after issuing the resume request. Call
await_running()if you need to wait for the devbox to reach therunningstate (contrast with the synchronous SDK, which blocks).- Parameters:
options (
Unpack[LongRequestOptions]) – Optional long-running request configuration- Returns:
Resumed devbox state info
- Return type:
- async keep_alive(**options)[source]¶
Extend the devbox timeout, preventing automatic shutdown.
Call this periodically for long-running workflows to prevent the devbox from being automatically shut down due to inactivity.
- Parameters:
options (
Unpack[LongRequestOptions]) – Optional long-running request configuration- Returns:
Response confirming the keep-alive request
- Return type:
- async snapshot_disk(**params)[source]¶
Create a disk snapshot of the devbox and wait for completion.
Captures the current state of the devbox disk, which can be used to create new devboxes with the same state.
- Parameters:
params (
Unpack[SDKDevboxSnapshotDiskParams]) – SeeSDKDevboxSnapshotDiskParamsfor available parameters- Returns:
Wrapper representing the completed snapshot
- Return type:
- async snapshot_disk_async(**params)[source]¶
Create a disk snapshot of the devbox asynchronously.
Starts the snapshot creation process and returns immediately without waiting for completion. Use snapshot.await_completed() to wait for completion.
- Parameters:
params (
Unpack[SDKDevboxSnapshotDiskAsyncParams]) – SeeSDKDevboxSnapshotDiskAsyncParamsfor available parameters- Returns:
Wrapper representing the snapshot request
- Return type:
- async close()[source]¶
Alias for
shutdown()to support common resource patterns.- Return type:
- property cmd: AsyncCommandInterface¶
Return the command execution interface.
- Returns:
Helper for running shell commands
- Return type:
- property file: AsyncFileInterface¶
Return the file operations interface.
- Returns:
Helper for reading/writing files
- Return type:
- property net: AsyncNetworkInterface¶
Return the networking interface.
- Returns:
Helper for SSH keys and tunnels
- Return type:
- class runloop_api_client.sdk.async_devbox.AsyncCommandInterface(devbox)[source]¶
Interface for executing commands on a devbox.
Accessed via devbox.cmd property. Provides exec() for synchronous execution and exec_async() for asynchronous execution with process management.
- async exec(**params)[source]¶
Execute a command synchronously and wait for completion.
- Parameters:
params (
Unpack[SDKDevboxExecuteParams]) – SeeSDKDevboxExecuteParamsfor available parameters- Returns:
Wrapper with exit status and output helpers
- Return type:
Example
>>> result = await devbox.cmd.exec(command="echo 'hello'") >>> print(await result.stdout()) >>> print(f"Exit code: {result.exit_code}")
- async exec_async(**params)[source]¶
Execute a command asynchronously without waiting for completion.
Starts command execution and returns immediately with an AsyncExecution object for process management. Use execution.result() to wait for completion or execution.kill() to terminate the process.
- Parameters:
params (
Unpack[SDKDevboxExecuteAsyncParams]) – SeeSDKDevboxExecuteAsyncParamsfor available parameters- Returns:
Handle for managing the running process
- Return type:
Example
>>> execution = await devbox.cmd.exec_async(command="sleep 10") >>> state = await execution.get_state() >>> print(f"Status: {state.status}") >>> await execution.kill() # Terminate early if needed
- class runloop_api_client.sdk.async_devbox.AsyncFileInterface(devbox)[source]¶
Interface for file operations on a devbox.
Accessed via devbox.file property. Provides coroutines for reading, writing, uploading, and downloading files.
- async read(**params)[source]¶
Read a file from the devbox.
- Parameters:
params (
Unpack[SDKDevboxReadFileContentsParams]) – SeeSDKDevboxReadFileContentsParamsfor available parameters- Returns:
File contents
- Return type:
Example
>>> content = await devbox.file.read(path="/home/user/data.txt") >>> print(content)
- async write(**params)[source]¶
Write contents to a file in the devbox.
Creates or overwrites the file at the specified path.
- Parameters:
params (
Unpack[SDKDevboxWriteFileContentsParams]) – SeeSDKDevboxWriteFileContentsParamsfor available parameters- Returns:
Execution metadata for the write command
- Return type:
Example
>>> await devbox.file.write(file_path="/home/user/config.json", contents='{"key": "value"}')
- async download(**params)[source]¶
Download a file from the devbox.
- Parameters:
params (
Unpack[SDKDevboxDownloadFileParams]) – SeeSDKDevboxDownloadFileParamsfor available parameters- Returns:
Raw file contents
- Return type:
Example
>>> data = await devbox.file.download(path="/home/user/output.bin") >>> with open("local_output.bin", "wb") as f: ... f.write(data)
- async upload(**params)[source]¶
Upload a file to the devbox.
- Parameters:
params (
Unpack[SDKDevboxUploadFileParams]) – SeeSDKDevboxUploadFileParamsfor available parameters- Returns:
API response confirming the upload
- Return type:
Example
>>> from pathlib import Path >>> await devbox.file.upload(path="/home/user/data.csv", file=Path("local_data.csv"))
- class runloop_api_client.sdk.async_devbox.AsyncNetworkInterface(devbox)[source]¶
Interface for networking operations on a devbox.
Accessed via devbox.net property. Provides coroutines for SSH access and tunneling.
- async create_ssh_key(**options)[source]¶
Create an SSH key for remote access to the devbox.
- Parameters:
options (
Unpack[LongRequestOptions]) – Optional long-running request configuration- Returns:
Response containing SSH connection info
- Return type:
Example
>>> ssh_key = await devbox.net.create_ssh_key() >>> print(f"SSH URL: {ssh_key.url}")
- async create_tunnel(**params)[source]¶
Create a network tunnel to expose a devbox port publicly.
- Parameters:
params (
Unpack[SDKDevboxCreateTunnelParams]) – SeeSDKDevboxCreateTunnelParamsfor available parameters- Returns:
Details about the public endpoint
- Return type:
Example
>>> tunnel = await devbox.net.create_tunnel(port=8080) >>> print(f"Public URL: {tunnel.url}")
- async remove_tunnel(**params)[source]¶
Remove a network tunnel, disabling public access to the port.
- Parameters:
params (
Unpack[SDKDevboxRemoveTunnelParams]) – SeeSDKDevboxRemoveTunnelParamsfor available parameters- Returns:
Response confirming the tunnel removal
- Return type:
Example
>>> await devbox.net.remove_tunnel(port=8080)