Skip to main content

Sandbox

__init__

Create a new desktop sandbox. By default, the sandbox is created from the desktop template. Arguments:
  • resolution: Startup the desktop with custom screen resolution. Defaults to (1024, 768)
  • dpi: Startup the desktop with custom DPI. Defaults to 96
  • display: Startup the desktop with custom display. Defaults to “:0”
  • template: Sandbox template name or ID
  • timeout: 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: Custom metadata for the sandbox
  • envs: Custom environment variables for the sandbox
  • api_key: E2B API Key to use for authentication, defaults to E2B_API_KEY environment variable
  • domain: E2B domain to use for authentication, defaults to E2B_DOMAIN environment variable
  • debug: If True, the sandbox will be created in debug mode, defaults to E2B_DEBUG environment variable
  • sandbox_id: Sandbox ID to connect to, defaults to E2B_SANDBOX_ID environment variable
  • request_timeout: Timeout for the request in seconds
Returns: sandbox instance for the new sandbox

screenshot

Take a screenshot and return it as a stream of bytes.

screenshot

Take a screenshot and return it as a bytearray.

screenshot

Take a screenshot and return it in the specified format. Arguments:
  • format: The format of the screenshot. Can be ‘bytes’, ‘blob’, or ‘stream’.
Returns: The screenshot in the specified format.

left_click

Left click on the current mouse position.

double_click

Double left click on the current mouse position.

right_click

Right click on the current mouse position.

middle_click

Middle click on the current mouse position.

scroll

Scroll the mouse wheel by the given amount. Arguments:
  • direction: The direction to scroll. Can be “up” or “down”.
  • amount: The amount to scroll.

move_mouse

Move the mouse to the given coordinates. Arguments:
  • x: The x coordinate.
  • y: The y coordinate.

get_cursor_position

Get the current cursor position. Raises:
  • RuntimeError: If the cursor position cannot be determined
Returns: A tuple with the x and y coordinates

get_screen_size

Get the current screen size. Raises:
  • RuntimeError: If the screen size cannot be determined
Returns: A tuple with the width and height

write

Write the given text at the current cursor position. Arguments:
  • text: The text to write.
  • chunk_size: The size of each chunk of text to write.
  • delay_in_ms: The delay between each chunk of text.

press

Press a key. Arguments:
  • key: The key to press (e.g. “enter”, “space”, “backspace”, etc.).

open

Open a file or a URL in the default application. Arguments:
  • file_or_url: The file or URL to open.