### Install E2B Desktop SDK using pip Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/examples/streaming-apps-python/README.md This command installs the E2B Desktop SDK, which is necessary for interacting with the E2B Desktop Sandbox. Ensure you have Python and pip installed. ```bash pip install e2b-desktop ``` -------------------------------- ### Install E2B Desktop SDK Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/examples/streaming-apps-javascript/README.md Installs the necessary E2B Desktop SDK package using npm. This is a prerequisite for using the E2B Desktop Sandbox functionalities. ```bash npm install @e2b/desktop ``` -------------------------------- ### Install E2B Desktop SDK Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/README.md Instructions for installing the E2B Desktop SDK for Python and JavaScript environments. This step is necessary before creating and managing sandboxes. ```bash pip install e2b-desktop ``` ```bash npm install @e2b/desktop ``` -------------------------------- ### Stream the entire desktop screen Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/packages/js-sdk/README.md This example shows how to initiate a stream of the entire desktop screen within the sandbox. It covers starting the stream, retrieving the stream URL, and stopping the stream when no longer needed. ```javascript import { Sandbox } from '@e2b/desktop' const desktop = await Sandbox.create() // Start the stream await desktop.stream.start() // Get stream URL const url = desktop.stream.getUrl() console.log(url) // Stop the stream await desktop.stream.stop() ``` -------------------------------- ### Stream Specific Application Window in E2B Sandbox Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/packages/python-sdk/README.md Provides an example of streaming a specific application's window. It includes notes on limitations such as needing the application to be open and only supporting one stream at a time. It shows how to get application window IDs and start streaming a specific one. ```python from e2b_desktop import Sandbox desktop = Sandbox.create() # Get current (active) window ID window_id = desktop.get_current_window_id() # Get all windows of the application window_ids = desktop.get_application_windows("Firefox") # Start the stream desktop.stream.start(window_id=window_ids[0]) # Stop the stream desktop.stream.stop() ``` -------------------------------- ### Stream Desktop Screen in E2B Sandbox (Python) Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/README.md Shows how to start streaming the entire desktop screen of an E2B sandbox. It includes methods to get the stream URL, with an option to make it view-only, and how to stop the stream. ```python from e2b_desktop import Sandbox desktop = Sandbox.create() # Start the stream desktop.stream.start() # Get stream URL url = desktop.stream.get_url() print(url) # Get stream URL and disable user interaction url = desktop.stream.get_url(view_only=True) print(url) # Stop the stream desktop.stream.stop() ``` -------------------------------- ### Launch Application Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-js-sdk/v1.9.1/sandbox/page.mdx Starts a specified application, optionally opening a given URI. This asynchronous method returns a Promise and takes the application name and an optional URI as parameters. ```typescript launch(application: string, uri?: string): Promise ``` -------------------------------- ### Launch application with optional URI in Python Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.7.2/sandbox/page.mdx Starts a specified application, optionally with a URI to handle. Accepts the application name as a string and an optional URI string. Returns nothing. ```python from typing import Optional def launch(application: str, uri: Optional[str] = None): # Function implementation to launch the application pass ``` -------------------------------- ### Launch Application Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v2.0.0/sandbox/page.mdx Starts a specified application, optionally with a URI to open within it. This function is the primary way to programmatically launch software. ```python def launch(application: str, uri: Optional[str] = None) ``` -------------------------------- ### Utility Functions Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.3.0/sandbox/page.mdx Get information about the sandbox environment. ```APIDOC ## Utility Functions ### Description Get information about the sandbox environment. ### Methods * `get_cursor_position() -> tuple[int, int]` * `get_screen_size() -> tuple[int, int]` * `wait(ms: int)` * `open(file_or_url: str)` ### Parameters #### `get_cursor_position` No parameters. #### `get_screen_size` No parameters. #### `wait` * `ms` (int) - The amount of time to wait in milliseconds. #### `open` * `file_or_url` (str) - The file or URL to open. ### Request Example ```python cursor_pos = sandbox.get_cursor_position() screen_size = sandbox.get_screen_size() sandbox.wait(1000) sandbox.open("https://example.com") ``` ### Response #### Success Response (200) * `get_cursor_position()`: Returns a tuple with the x and y coordinates of the cursor. * `get_screen_size()`: Returns a tuple with the width and height of the screen. * `wait(ms)`: Does not return a value. * `open(file_or_url)`: Does not return a value. #### Response Example ```python # Example for get_cursor_position print(cursor_pos) # Output: (100, 200) # Example for get_screen_size print(screen_size) # Output: (1920, 1080) ``` ### Errors #### `get_cursor_position` * `RuntimeError`: If the cursor position cannot be determined. #### `get_screen_size` * `RuntimeError`: If the screen size cannot be determined. ``` -------------------------------- ### Run E2B Desktop Sandbox and Stream Applications (Python) Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/examples/streaming-apps-python/README.md This Python script demonstrates how to create a desktop sandbox, launch applications like Google Chrome or VS Code, stream their windows, interact with them by writing text and pressing keys, and manage the streaming lifecycle. It requires an E2B API key set as an environment variable. ```python from e2b_desktop import Sandbox # Create a new desktop sandbox desktop = Sandbox.create() print('Desktop sandbox created', desktop.sandbox_id) # Launch an application print('Launching Google Chrome') desktop.launch('google-chrome') # or vscode, firefox, etc. # Wait 15s for the application to open desktop.wait(15000) # Stream the application's window # Note: there can be only one stream at a time # You need to stop the current stream before streaming another application print('Starting to stream Google Chrome') desktop.stream.start( window_id=desktop.get_current_window_id(), # if not provided the whole desktop will be streamed require_auth=True, ) # Get the stream auth key auth_key = desktop.stream.get_auth_key() # Print the stream URL print('Stream URL:', desktop.stream.get_url(auth_key=auth_key)) # Do some actions in the application print('Writing to Google Chrome') desktop.write('What is the capital of Germany?') print('Pressing Enter') desktop.press('enter') # wait 15s for page to load print('Waiting 15s') desktop.wait(15000) # Stop the stream print('Stopping the stream') desktop.stream.stop() # Open another application print('Launching VS Code') desktop.launch('code') # Wait 15s for the application to open desktop.wait(15000) # Start streaming the new application print('Starting to stream VS Code') desktop.stream.start( window_id=desktop.get_current_window_id(), # if not provided the whole desktop will be streamed require_auth=True, ) # Get the stream auth key auth_key2 = desktop.stream.get_auth_key() # Print the stream URL print('Stream URL:', desktop.stream.get_url(auth_key=auth_key2)) # Kill the sandbox after the tasks are finished # desktop.kill() ``` -------------------------------- ### Launch Application with E2B Desktop SDK Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/packages/js-sdk/README.md Launch a specified application within the sandbox environment. The 'launch' method takes the application name as an argument. Ensure the application is installed in the sandbox. ```javascript import { Sandbox } from '@e2b/desktop' const desktop = await Sandbox.create() // Launch the application await desktop.launch('google-chrome') ``` -------------------------------- ### Create and Stream Desktop Sandbox Applications (JavaScript) Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/examples/streaming-apps-javascript/README.md Demonstrates creating a desktop sandbox, launching applications ('google-chrome', 'code'), streaming their windows, interacting with them via text input and key presses, and managing stream authentication. It highlights the limitation of only one stream active at a time and the process to switch between streaming different applications. ```javascript import { Sandbox } from '@e2b/desktop' // Start a new desktop sandbox const desktop = await Sandbox.create() console.log('Desktop sandbox created', desktop.sandboxId) // Launch an application console.log('Launching Google Chrome') await desktop.launch('google-chrome') // or vscode, firefox, etc. // Wait 15s for the application to open await desktop.wait(15000) // Stream the application's window // Note: there can be only one stream at a time // You need to stop the current stream before streaming another application console.log('Starting to stream Google Chrome') await desktop.stream.start({ windowId: await desktop.getCurrentWindowId(), // if not provided the whole desktop will be streamed requireAuth: true, }) // Get the stream auth key const authKey = desktop.stream.getAuthKey() // Print the stream URL console.log('Stream URL:', desktop.stream.getUrl({ authKey })) // Do some actions in the application console.log('Writing to Google Chrome') await desktop.write('What is the capital of Germany?') console.log('Pressing Enter') await desktop.press('Enter') // wait 15s for page to load console.log('Waiting 15s') await desktop.wait(15000) // Stop the stream console.log('Stopping the stream') await desktop.stream.stop() // Open another application console.log('Launching VS Code') await desktop.launch('code') // Wait 15s for the application to open await desktop.wait(15000) // Start streaming the new application console.log('Starting to stream VS Code') await desktop.stream.start({ windowId: await desktop.getCurrentWindowId(), // if not provided the whole desktop will be streamed requireAuth: true, }) // Get the stream auth key const authKey2 = desktop.stream.getAuthKey() // Print the stream URL console.log('Stream URL:', desktop.stream.getUrl({ authKey: authKey2 })) // Kill the sandbox after the tasks are finished // await desktop.kill() ``` -------------------------------- ### Create and Launch Application in E2B Desktop Sandbox (JavaScript) Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/README.md Demonstrates how to create a new E2B Desktop sandbox using JavaScript, launch an application like Google Chrome, wait for it to open, and stream its window. It also covers getting the stream URL and authentication key if required. The sandbox can be killed when finished. ```javascript import { Sandbox } from '@e2b/desktop' // Start a new desktop sandbox const desktop = await Sandbox.create() // Launch an application await desktop.launch('google-chrome') // or vscode, firefox, etc. // Wait 10s for the application to open await desktop.wait(10000) // Stream the application's window // Note: There can be only one stream at a time // You need to stop the current stream before streaming another application await desktop.stream.start({ windowId: await desktop.getCurrentWindowId(), // if not provided the whole desktop will be streamed requireAuth: true, }) // Get the stream auth key const authKey = desktop.stream.getAuthKey() // Print the stream URL console.log('Stream URL:', desktop.stream.getUrl({ authKey })) // Kill the sandbox after the tasks are finished // await desktop.kill() ``` -------------------------------- ### Sandbox Initialization Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.0.3/sandbox/page.mdx Initialize a new desktop sandbox with various configuration options. ```APIDOC ## Sandbox Initialization ### Description Create a new desktop sandbox. By default, the sandbox is created from the `desktop` template. ### Method __init__ ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **resolution** (Optional[Tuple[int, int]]) - Startup the desktop with custom screen resolution. Defaults to (1024, 768) - **dpi** (Optional[int]) - Startup the desktop with custom DPI. Defaults to 96 - **display** (Optional[str]) - Startup the desktop with custom display. Defaults to ":0" - **template** (Optional[str]) - Sandbox template name or ID - **timeout** (Optional[int]) - Timeout for the sandbox in seconds, default to 300 seconds. Maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users - **metadata** (Optional[Dict[str, str]]) - Custom metadata for the sandbox - **envs** (Optional[Dict[str, str]]) - Custom environment variables for the sandbox - **api_key** (Optional[str]) - E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable - **domain** (Optional[str]) - E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable - **debug** (Optional[bool]) - If True, the sandbox will be created in debug mode, defaults to `E2B_DEBUG` environment variable - **sandbox_id** (Optional[str]) - Sandbox ID to connect to, defaults to `E2B_SANDBOX_ID` environment variable - **request_timeout** (Optional[float]) - Timeout for the request in seconds ### Request Example ```python Sandbox( resolution=(1920, 1080), dpi=120, template="custom-template-id", timeout=600, api_key="my-api-key" ) ``` ### Response #### Success Response (200) - **sandbox instance** (object) - An instance of the Sandbox class for the newly created sandbox. #### Response Example ```python # Assuming a successful sandbox creation sandbox = Sandbox() print(sandbox) ``` ``` -------------------------------- ### Stream Desktop Screen with Password Protection Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/packages/python-sdk/README.md Demonstrates how to start streaming the desktop screen with authentication enabled, retrieve the generated authentication key, and then get the secure stream URL. The stream is stopped afterward. ```python from e2b_desktop import Sandbox desktop = Sandbox.create() # Start the stream desktop.stream.start( require_auth=True # Enable authentication with an auto-generated key ) # Retrieve the authentication key auth_key = desktop.stream.get_auth_key() # Get stream URL url = desktop.stream.get_url(auth_key=auth_key) print(url) # Stop the stream desktop.stream.stop() ``` -------------------------------- ### Create and Interact with a Desktop Sandbox Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/packages/js-sdk/README.md Demonstrates the basic workflow of creating a new desktop sandbox, launching an application like Google Chrome, waiting for it to load, and setting up a stream for its window. It also shows how to retrieve stream authentication details. ```javascript import { Sandbox } from '@e2b/desktop' // Start a new desktop sandbox const desktop = await Sandbox.create() // Launch an application await desktop.launch('google-chrome') // or vscode, firefox, etc. // Wait 10s for the application to open await desktop.wait(10000) // Stream the application's window // Note: there can be only one stream at a time // You need to stop the current stream before streaming another application await desktop.stream.start({ windowId: await desktop.getCurrentWindowId(), // if not provided the whole desktop will be streamed requireAuth: true, }) // Get the stream auth key const authKey = desktop.stream.getAuthKey() // Print the stream URL console.log('Stream URL:', desktop.stream.getUrl({ authKey })) // Kill the sandbox after the tasks are finished // await desktop.kill() ``` -------------------------------- ### Create and Launch Application in E2B Desktop Sandbox Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/packages/python-sdk/README.md Demonstrates creating a new desktop sandbox, launching a specified application (e.g., Google Chrome), waiting for it to open, and streaming its window. It also shows how to retrieve the stream authentication key and URL. The sandbox can be killed afterwards. ```python from e2b_desktop import Sandbox # Create a new desktop sandbox desktop = Sandbox.create() # Launch an application desktop.launch('google-chrome') # or vscode, firefox, etc. # Wait 10s for the application to open desktop.wait(10000) # Stream the application's window # Note: There can be only one stream at a time # You need to stop the current stream before streaming another application desktop.stream.start( window_id=desktop.get_current_window_id(), # if not provided the whole desktop will be streamed require_auth=True ) # Get the stream auth key auth_key = desktop.stream.get_auth_key() # Print the stream URL print('Stream URL:', desktop.stream.get_url(auth_key=auth_key)) # Kill the sandbox after the tasks are finished # desktop.kill() ``` -------------------------------- ### Sandbox Initialization Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.6.1/sandbox/page.mdx Initializes a new desktop sandbox with various configuration options. ```APIDOC ## Sandbox Initialization ### Description Initializes a new desktop sandbox. By default, the sandbox is created from the `desktop` template. ### Method `__init__` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * `resolution` (Optional[Tuple[int, int]]) - Startup the desktop with custom screen resolution. Defaults to (1024, 768) * `dpi` (Optional[int]) - Startup the desktop with custom DPI. Defaults to 96 * `display` (Optional[str]) - Startup the desktop with custom display. Defaults to ":0" * `template` (Optional[str]) - Sandbox template name or ID * `timeout` (Optional[int]) - Timeout for the sandbox in **seconds**, default to 300 seconds. Maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users * `metadata` (Optional[Dict[str, str]]) - Custom metadata for the sandbox * `envs` (Optional[Dict[str, str]]) - Custom environment variables for the sandbox * `api_key` (Optional[str]) - E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable * `domain` (Optional[str]) - E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable * `debug` (Optional[bool]) - If True, the sandbox will be created in debug mode, defaults to `E2B_DEBUG` environment variable * `sandbox_id` (Optional[str]) - Sandbox ID to connect to, defaults to `E2B_SANDBOX_ID` environment variable * `request_timeout` (Optional[float]) - Timeout for the request in **seconds** ### Request Example ```python from e2b_devdesktop_sdk import Sandbox sandbox = Sandbox( resolution=(1920, 1080), dpi=120, template="my-custom-template", timeout=600, api_key="YOUR_API_KEY" ) ``` ### Response #### Success Response (200) Returns a sandbox instance for the new sandbox. #### Response Example ```python # sandbox instance object is returned ``` ``` -------------------------------- ### Stream Desktop Screen in E2B Sandbox (JavaScript) Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/README.md Shows how to start streaming the entire desktop screen of an E2B sandbox using JavaScript. It includes methods to get the stream URL, with an option to make it view-only, and how to stop the stream. ```javascript import { Sandbox } from '@e2b/desktop' const desktop = await Sandbox.create() // Start the stream await desktop.stream.start() // Get stream URL const url = desktop.stream.getUrl() console.log(url) // Get stream URL and disable user interaction const url = desktop.stream.getUrl({ viewOnly: true }) console.log(url) // Stop the stream await desktop.stream.stop() ``` -------------------------------- ### Sandbox Initialization Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.6.5/sandbox/page.mdx Initialize a new desktop sandbox with various configuration options. ```APIDOC ## Sandbox Initialization ### Description Create a new desktop sandbox. By default, the sandbox is created from the `desktop` template. ### Method `__init__` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **resolution** (Optional[Tuple[int, int]]) - Startup the desktop with custom screen resolution. Defaults to (1024, 768) - **dpi** (Optional[int]) - Startup the desktop with custom DPI. Defaults to 96 - **display** (Optional[str]) - Startup the desktop with custom display. Defaults to ":0" - **template** (Optional[str]) - Sandbox template name or ID - **timeout** (Optional[int]) - Timeout for the sandbox in seconds, default to 300 seconds. Maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users - **metadata** (Optional[Dict[str, str]]) - Custom metadata for the sandbox - **envs** (Optional[Dict[str, str]]) - Custom environment variables for the sandbox - **api_key** (Optional[str]) - E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable - **domain** (Optional[str]) - E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable - **debug** (Optional[bool]) - If True, the sandbox will be created in debug mode, defaults to `E2B_DEBUG` environment variable - **sandbox_id** (Optional[str]) - Sandbox ID to connect to, defaults to `E2B_SANDBOX_ID` environment variable - **request_timeout** (Optional[float]) - Timeout for the request in seconds ### Request Example ```python from e2b_dev.desktop_templates_sdk import Sandbox sandbox = Sandbox( resolution=(1920, 1080), timeout=600, api_key="your_api_key" ) ``` ### Response #### Success Response (200) - **sandbox instance** (object) - An instance of the Sandbox class for the newly created sandbox. #### Response Example ```python # Assuming the Sandbox class is successfully instantiated # The actual returned object would be an instance of Sandbox ``` ``` -------------------------------- ### Stream a specific application window Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/packages/js-sdk/README.md This example details how to stream a specific application's window within the sandbox. It includes obtaining window IDs for an application like Firefox and starting a stream for the first found window. Note the limitations regarding stream creation and application state. ```javascript import { Sandbox } from '@e2b/desktop' const desktop = await Sandbox.create() // Get current (active) window ID const windowId = await desktop.getCurrentWindowId() // Get all windows of the application const windowIds = await desktop.getApplicationWindows('Firefox') // Start the stream await desktop.stream.start({ windowId: windowIds[0] }) // Stop the stream await desktop.stream.stop() ``` -------------------------------- ### Initialize Sandbox in Python Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.0.3/sandbox/page.mdx Creates a new desktop sandbox instance with configurable options such as resolution, DPI, template, timeout, and authentication details. Defaults to the 'desktop' template if none is specified. Handles API keys and domains via environment variables. ```python class Sandbox(SandboxBase) def __init__(resolution: Optional[Tuple[int, int]] = None, dpi: Optional[int] = None, display: Optional[str] = None, template: Optional[str] = None, timeout: Optional[int] = None, metadata: Optional[Dict[str, str]] = None, envs: Optional[Dict[str, str]] = None, api_key: Optional[str] = None, domain: Optional[str] = None, debug: Optional[bool] = None, sandbox_id: Optional[str] = None, request_timeout: Optional[float] = None) ``` -------------------------------- ### Control Desktop Windows: Python and JavaScript Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/README.md Manage desktop windows by getting the current active window ID, retrieving all windows associated with a specific application, and starting or stopping a desktop stream. This functionality requires the Sandbox module from the e2b_desktop library. It returns window identifiers and controls streaming operations. ```python from e2b_desktop import Sandbox desktop = Sandbox.create() # Get current (active) window ID window_id = desktop.get_current_window_id() # Get all windows of the application window_ids = desktop.get_application_windows("Firefox") # Start the stream desktop.stream.start(window_id=window_ids[0]) # Stop the stream desktop.stream.stop() ``` ```javascript import { Sandbox } from '@e2b/desktop' const desktop = await Sandbox.create() // Get current (active) window ID const windowId = await desktop.getCurrentWindowId() // Get all windows of the application const windowIds = await desktop.getApplicationWindows('Firefox') // Start the stream await desktop.stream.start({ windowId: windowIds[0] }) // Stop the stream await desktop.stream.stop() ``` -------------------------------- ### Sandbox Initialization Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.6.4/sandbox/page.mdx Initializes a new desktop sandbox with various configuration options. ```APIDOC ## Sandbox Initialization ### Description Create a new desktop sandbox. By default, the sandbox is created from the `desktop` template. ### Method `__init__` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **resolution** (Optional[Tuple[int, int]]) - Startup the desktop with custom screen resolution. Defaults to (1024, 768) - **dpi** (Optional[int]) - Startup the desktop with custom DPI. Defaults to 96 - **display** (Optional[str]) - Startup the desktop with custom display. Defaults to ":0" - **template** (Optional[str]) - Sandbox template name or ID - **timeout** (Optional[int]) - Timeout for the sandbox in **seconds**, default to 300 seconds. Maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users - **metadata** (Optional[Dict[str, str]]) - Custom metadata for the sandbox - **envs** (Optional[Dict[str, str]]) - Custom environment variables for the sandbox - **api_key** (Optional[str]) - E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable - **domain** (Optional[str]) - E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable - **debug** (Optional[bool]) - If True, the sandbox will be created in debug mode, defaults to `E2B_DEBUG` environment variable - **sandbox_id** (Optional[str]) - Sandbox ID to connect to, defaults to `E2B_SANDBOX_ID` environment variable - **request_timeout** (Optional[float]) - Timeout for the request in **seconds** ### Request Example ```python Sandbox(resolution=(1920, 1080), api_key="your_api_key") ``` ### Response #### Success Response (200) - **sandbox instance** - An instance of the Sandbox class for the newly created sandbox. #### Response Example ```python # Example of a sandbox instance (conceptual) sandbox = Sandbox() ``` ``` -------------------------------- ### Sandbox Initialization Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.6.0/sandbox/page.mdx Initializes a new desktop sandbox with various configuration options. ```APIDOC ## Sandbox Initialization ### Description Creates a new desktop sandbox. By default, the sandbox is created from the `desktop` template. ### Method `__init__` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * `resolution` (Optional[Tuple[int, int]]) - Startup the desktop with custom screen resolution. Defaults to (1024, 768) * `dpi` (Optional[int]) - Startup the desktop with custom DPI. Defaults to 96 * `display` (Optional[str]) - Startup the desktop with custom display. Defaults to ":0" * `template` (Optional[str]) - Sandbox template name or ID * `timeout` (Optional[int]) - Timeout for the sandbox in seconds, default to 300 seconds. Maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users * `metadata` (Optional[Dict[str, str]]) - Custom metadata for the sandbox * `envs` (Optional[Dict[str, str]]) - Custom environment variables for the sandbox * `api_key` (Optional[str]) - E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable * `domain` (Optional[str]) - E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable * `debug` (Optional[bool]) - If True, the sandbox will be created in debug mode, defaults to `E2B_DEBUG` environment variable * `sandbox_id` (Optional[str]) - Sandbox ID to connect to, defaults to `E2B_SANDBOX_ID` environment variable * `request_timeout` (Optional[float]) - Timeout for the request in seconds ### Request Example ```python Sandbox(resolution=(1920, 1080), dpi=120, template="custom-template") ``` ### Response #### Success Response (200) - `sandbox_instance` (object) - An instance of the Sandbox class for the new sandbox. #### Response Example ```python # Example sandbox instance creation sandbox = Sandbox() ``` ``` -------------------------------- ### Sandbox Initialization Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.6.3/sandbox/page.mdx Initializes a new desktop sandbox with various configuration options. ```APIDOC ## Sandbox Initialization ### Description Create a new desktop sandbox. By default, the sandbox is created from the `desktop` template. ### Method __init__ ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **resolution** (Optional[Tuple[int, int]]) - Startup the desktop with custom screen resolution. Defaults to (1024, 768) - **dpi** (Optional[int]) - Startup the desktop with custom DPI. Defaults to 96 - **display** (Optional[str]) - Startup the desktop with custom display. Defaults to ":0" - **template** (Optional[str]) - Sandbox template name or ID - **timeout** (Optional[int]) - Timeout for the sandbox in seconds, default to 300 seconds. Maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users - **metadata** (Optional[Dict[str, str]]) - Custom metadata for the sandbox - **envs** (Optional[Dict[str, str]]) - Custom environment variables for the sandbox - **api_key** (Optional[str]) - E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable - **domain** (Optional[str]) - E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable - **debug** (Optional[bool]) - If True, the sandbox will be created in debug mode, defaults to `E2B_DEBUG` environment variable - **sandbox_id** (Optional[str]) - Sandbox ID to connect to, defaults to `E2B_SANDBOX_ID` environment variable - **request_timeout** (Optional[float]) - Timeout for the request in seconds ### Request Example ```python from e2b_dev.desktop_templates_sdk import Sandbox sandbox = Sandbox(resolution=(1280, 720), timeout=600) ``` ### Response #### Success Response (200) - **sandbox instance** (object) - An instance of the Sandbox class for the newly created sandbox. #### Response Example ```python # Example sandbox instance is not directly representable as JSON print(sandbox) ``` ``` -------------------------------- ### Control Window Actions in E2B Sandbox Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/packages/python-sdk/README.md Shows how to interact with application windows, including getting the current active window ID, retrieving all window IDs for a specific application (e.g., Firefox), and getting the title of a specific window. ```python from e2b_desktop import Sandbox desktop = Sandbox.create() # Get current (active) window ID window_id = desktop.get_current_window_id() # Get all windows of the application window_ids = desktop.get_application_windows("Firefox") # Get window title title = desktop.get_window_title(window_id) ``` -------------------------------- ### Stream E2B Sandbox with Password Protection (Python) Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/README.md Demonstrates how to start a screen stream for an E2B sandbox that requires authentication. It shows how to enable this feature, retrieve the auto-generated authentication key, and construct the stream URL. ```python from e2b_desktop import Sandbox desktop = Sandbox.create() # Start the stream desktop.stream.start( require_auth=True # Require authentication with an auto-generated key ) # Retrieve the authentication key auth_key = desktop.stream.get_auth_key() # Get stream URL url = desktop.stream.get_url(auth_key=auth_key) print(url) # Stop the stream desktop.stream.stop() ``` -------------------------------- ### Sandbox Initialization Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.7.1/sandbox/page.mdx Initializes a new desktop sandbox environment. You can customize resolution, DPI, template, timeouts, and more. ```APIDOC ## Sandbox Initialization ### Description Create a new desktop sandbox. By default, the sandbox is created from the `desktop` template. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **resolution** (Optional[Tuple[int, int]]) - Startup the desktop with custom screen resolution. Defaults to (1024, 768) - **dpi** (Optional[int]) - Startup the desktop with custom DPI. Defaults to 96 - **display** (Optional[str]) - Startup the desktop with custom display. Defaults to ":0" - **template** (Optional[str]) - Sandbox template name or ID - **timeout** (Optional[int]) - Timeout for the sandbox in **seconds**, default to 300 seconds. Maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users - **metadata** (Optional[Dict[str, str]]) - Custom metadata for the sandbox - **envs** (Optional[Dict[str, str]]) - Custom environment variables for the sandbox - **api_key** (Optional[str]) - E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable - **domain** (Optional[str]) - E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable - **debug** (Optional[bool]) - If True, the sandbox will be created in debug mode, defaults to `E2B_DEBUG` environment variable - **sandbox_id** (Optional[str]) - Sandbox ID to connect to, defaults to `E2B_SANDBOX_ID` environment variable - **request_timeout** (Optional[float]) - Timeout for the request in **seconds** ### Request Example ```python from e2b_dev.sandbox import Sandbox sandbox = Sandbox(resolution=(1920, 1080), dpi=120, timeout=600) ``` ### Response #### Success Response (200) - **sandbox instance** (Sandbox) - The initialized sandbox instance. #### Response Example ```python # No direct response example for initialization, but the sandbox object is returned. ``` ``` -------------------------------- ### Get Cursor and Screen Information in Python Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.0.3/sandbox/page.mdx Retrieves current information about the sandbox's display. Functions are provided to get the cursor's current position (x, y coordinates) and the overall screen dimensions (width, height). These operations may raise a RuntimeError if the information cannot be determined. ```python def get_cursor_position() -> tuple[int, int] ``` ```python def get_screen_size() -> tuple[int, int] ``` -------------------------------- ### Sandbox Initialization Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.5.2/sandbox/page.mdx Initializes a new desktop sandbox with various configuration options. ```APIDOC ## Sandbox Initialization ### Description Initializes a new desktop sandbox with various configuration options. ### Method `__init__` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **resolution** (Optional[Tuple[int, int]]) - Startup the desktop with custom screen resolution. Defaults to (1024, 768) - **dpi** (Optional[int]) - Startup the desktop with custom DPI. Defaults to 96 - **display** (Optional[str]) - Startup the desktop with custom display. Defaults to ":0" - **template** (Optional[str]) - Sandbox template name or ID - **timeout** (Optional[int]) - Timeout for the sandbox in seconds, default to 300 seconds. Maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users - **metadata** (Optional[Dict[str, str]]) - Custom metadata for the sandbox - **envs** (Optional[Dict[str, str]]) - Custom environment variables for the sandbox - **api_key** (Optional[str]) - E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable - **domain** (Optional[str]) - E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable - **debug** (Optional[bool]) - If True, the sandbox will be created in debug mode, defaults to `E2B_DEBUG` environment variable - **sandbox_id** (Optional[str]) - Sandbox ID to connect to, defaults to `E2B_SANDBOX_ID` environment variable - **request_timeout** (Optional[float]) - Timeout for the request in seconds ### Request Example ```python Sandbox(resolution=(1920, 1080), api_key="my_api_key") ``` ### Response #### Success Response (200) - **sandbox instance** (Sandbox) - A sandbox instance for the new sandbox #### Response Example ```python # No specific example, returns a sandbox instance ``` ``` -------------------------------- ### Screen Information API Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-js-sdk/v1.8.0/sandbox/page.mdx Get information about the screen. ```APIDOC ## Screen Information API ### Description Provides methods for retrieving screen-related information. ### Methods #### getCursorPosition() Retrieves the current position of the mouse cursor. - **Method**: `GET` (or similar, depending on actual implementation) - **Endpoint**: `/screen/cursor/position` - **Response**: - **Success Response (200)**: - `CursorPosition` (object) - An object containing `x` and `y` coordinates. - `x` (number) - The x-coordinate of the cursor. - `y` (number) - The y-coordinate of the cursor. - **Error Response**: - `Error` - If cursor position cannot be determined. #### getScreenSize() Retrieves the dimensions of the current screen. - **Method**: `GET` (or similar, depending on actual implementation) - **Endpoint**: `/screen/size` - **Response**: - **Success Response (200)**: - `ScreenSize` (object) - An object containing `width` and `height`. - `width` (number) - The width of the screen. - `height` (number) - The height of the screen. - **Error Response**: - `Error` - If screen size cannot be determined. ``` -------------------------------- ### Screen Size Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-js-sdk/v1.6.2/sandbox/page.mdx API endpoints for getting screen dimensions. ```APIDOC ## GET /screen/size ### Description Retrieves the current screen dimensions. ### Method GET ### Endpoint /screen/size ### Response #### Success Response (200) - **width** (number) - The width of the screen. - **height** (number) - The height of the screen. #### Error Response (500) - **error** (string) - Message indicating the screen size could not be determined. ### Response Example ```json { "width": 1920, "height": 1080 } ``` ``` -------------------------------- ### Sandbox Initialization Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.7.4/sandbox/page.mdx Initializes a new desktop sandbox instance with customizable options for resolution, DPI, display, template, timeouts, metadata, environment variables, API keys, domains, debug mode, sandbox ID, request timeouts, and proxy settings. ```APIDOC ## Sandbox Initialization ### Description Create a new desktop sandbox. By default, the sandbox is created from the `desktop` template. ### Method `__init__` ### Parameters #### Initialization Parameters - **resolution** (Optional[Tuple[int, int]]) - Optional - Startup the desktop with custom screen resolution. Defaults to (1024, 768). - **dpi** (Optional[int]) - Optional - Startup the desktop with custom DPI. Defaults to 96. - **display** (Optional[str]) - Optional - Startup the desktop with custom display. Defaults to ":0". - **template** (Optional[str]) - Optional - Sandbox template name or ID. - **timeout** (Optional[int]) - Optional - Timeout for the sandbox in seconds, default to 300 seconds. Maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users. - **metadata** (Optional[Dict[str, str]]) - Optional - Custom metadata for the sandbox. - **envs** (Optional[Dict[str, str]]) - Optional - Custom environment variables for the sandbox. - **api_key** (Optional[str]) - Optional - E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable. - **domain** (Optional[str]) - Optional - E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable. - **debug** (Optional[bool]) - Optional - If True, the sandbox will be created in debug mode, defaults to `E2B_DEBUG` environment variable. - **sandbox_id** (Optional[str]) - Optional - Sandbox ID to connect to, defaults to `E2B_SANDBOX_ID` environment variable. - **request_timeout** (Optional[float]) - Optional - Timeout for the request in seconds. - **proxy** (Optional[ProxyTypes]) - Optional - Proxy to use for the request and for the requests made to the returned sandbox. ### Returns sandbox instance for the new sandbox ``` -------------------------------- ### Sandbox Initialization Source: https://github.com/e2b-dev/desktop-templates-sdk/blob/main/sdk-reference/desktop-python-sdk/v1.3.0/sandbox/page.mdx Initialize a new desktop sandbox with various configuration options. ```APIDOC ## Sandbox Initialization ### Description Initialize a new desktop sandbox with various configuration options. ### Method `__init__` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * `resolution` (Optional[Tuple[int, int]]) - Startup the desktop with custom screen resolution. Defaults to (1024, 768) * `dpi` (Optional[int]) - Startup the desktop with custom DPI. Defaults to 96 * `display` (Optional[str]) - Startup the desktop with custom display. Defaults to ":0" * `template` (Optional[str]) - Sandbox template name or ID * `timeout` (Optional[int]) - Timeout for the sandbox in **seconds**, default to 300 seconds. Maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users * `metadata` (Optional[Dict[str, str]]) - Custom metadata for the sandbox * `envs` (Optional[Dict[str, str]]) - Custom environment variables for the sandbox * `api_key` (Optional[str]) - E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable * `domain` (Optional[str]) - E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable * `debug` (Optional[bool]) - If True, the sandbox will be created in debug mode, defaults to `E2B_DEBUG` environment variable * `sandbox_id` (Optional[str]) - Sandbox ID to connect to, defaults to `E2B_SANDBOX_ID` environment variable * `request_timeout` (Optional[float]) - Timeout for the request in **seconds** ### Request Example ```python from e2b import Sandbox sandbox = Sandbox(resolution=(1920, 1080), timeout=600) ``` ### Response #### Success Response (200) Returns a sandbox instance for the new sandbox. #### Response Example ```python # Sandbox instance is returned ``` ```