Devbox¶
The Devbox class provides synchronous methods for managing and interacting with a devbox instance.
Synchronous devbox resource class.
- class runloop_api_client.sdk.devbox.Devbox(client, devbox_id)[source]¶
High-level interface for managing a Runloop devbox.
This class provides a Pythonic, object-oriented API for interacting with devboxes, including command execution, file operations, networking, and lifecycle management.
The Devbox class supports context manager protocol for automatic cleanup.
Example
>>> with sdk.devbox.create(name="my-devbox") as devbox: ... result = devbox.cmd.exec("echo 'hello'") ... print(result.stdout()) # Devbox is automatically shutdown on exit
- get_info(**options)[source]¶
Retrieve current devbox status and metadata.
- Parameters:
options (
Unpack[BaseRequestOptions]) – Optional request configuration- Returns:
Current devbox state info
- Return type:
- await_running(*, polling_config=None)[source]¶
Wait for the devbox to reach running state.
Blocks until the devbox is running or the polling timeout is reached.
- Parameters:
polling_config (PollingConfig | None, optional) – Optional configuration for polling behavior (timeout, interval), defaults to None
- Returns:
Devbox state info after it reaches running status
- Return type:
- await_suspended(*, polling_config=None)[source]¶
Wait for the devbox to reach suspended state.
Blocks until the devbox is suspended or the polling timeout is reached.
- Parameters:
polling_config (PollingConfig | None, optional) – Optional configuration for polling behavior (timeout, interval), defaults to None
- Returns:
Devbox state info after it reaches suspended status
- Return type:
- shutdown(**options)[source]¶
Shutdown the devbox, terminating all processes and releasing resources.
- Parameters:
options (
Unpack[LongRequestOptions]) – Long-running request configuration (timeouts, retries, etc.)- Returns:
Final devbox state info
- Return type:
- suspend(**options)[source]¶
Suspend the devbox, pausing execution while preserving state.
This saves resources while maintaining the devbox state for later resumption. Waits for the devbox to reach suspended state before returning.
- Parameters:
options (
Unpack[LongPollingRequestOptions]) – Optional long-running request and polling configuration- Returns:
Suspended devbox state info
- Return type:
- resume(**options)[source]¶
Resume a suspended devbox, restoring it to running state.
Waits for the devbox to reach running state before returning.
- Parameters:
options (
Unpack[LongPollingRequestOptions]) – Optional long-running request and polling configuration- Returns:
Resumed devbox state info
- Return type:
- 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:
- 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:
- 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 (may still be processing)
- Return type:
- close()[source]¶
Alias for
shutdown()to support common resource patterns.- Return type:
- property cmd: CommandInterface¶
Return the command execution interface.
- Returns:
Helper for running shell commands
- Return type:
- property file: FileInterface¶
Return the file operations interface.
- Returns:
Helper for reading/writing files
- Return type:
- property net: NetworkInterface¶
Return the networking interface.
- Returns:
Helper for SSH keys and tunnels
- Return type:
- class runloop_api_client.sdk.devbox.CommandInterface(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.
- 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 = devbox.cmd.exec(command="ls -la") >>> print(result.stdout()) >>> print(f"Exit code: {result.exit_code}")
- exec_async(**params)[source]¶
Execute a command asynchronously without waiting for completion.
Starts command execution and returns immediately with an Execution 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 = devbox.cmd.exec_async(command="sleep 10") >>> state = execution.get_state() >>> print(f"Status: {state.status}") >>> execution.kill() # Terminate early if needed
- class runloop_api_client.sdk.devbox.FileInterface(devbox)[source]¶
Interface for file operations on a devbox.
Accessed via devbox.file property. Provides methods for reading, writing, uploading, and downloading files.
- read(**params)[source]¶
Read a file from the devbox.
- Parameters:
params (
Unpack[SDKDevboxReadFileContentsParams]) – SeeSDKDevboxReadFileContentsParamsfor available parameters- Returns:
File contents
- Return type:
Example
>>> content = devbox.file.read("/home/user/data.txt") >>> print(content)
- 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
>>> devbox.file.write(file_path="/home/user/config.json", contents='{"key": "value"}')
- download(**params)[source]¶
Download a file from the devbox.
- Parameters:
params (
Unpack[SDKDevboxDownloadFileParams]) – SeeSDKDevboxDownloadFileParamsfor available parameters- Returns:
Raw file contents
- Return type:
Example
>>> data = devbox.file.download("/home/user/output.bin") >>> with open("local_output.bin", "wb") as f: ... f.write(data)
- 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 >>> devbox.file.upload("/home/user/data.csv", Path("local_data.csv"))
- class runloop_api_client.sdk.devbox.NetworkInterface(devbox)[source]¶
Interface for network operations on a devbox.
Accessed via devbox.net property. Provides methods for SSH access and tunneling.
- 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 = devbox.net.create_ssh_key() >>> print(f"SSH URL: {ssh_key.url}")
- 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 = devbox.net.create_tunnel(port=8080) >>> print(f"Public URL: {tunnel.url}")
- 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
>>> devbox.net.remove_tunnel(port=8080)