Skip to main content

E2B Desktop Sandbox - Deskstop sandbox in cloud powered by E2B

Project description

E2B Desktop Sandbox - Virtual Computer for Computer Use

E2B Desktop Sandbox is a secure virtual desktop ready for Computer Use. Powered by E2B.

Each sandbox is isolated from the others and can be customized with any dependencies you want.

Desktop Sandbox

Examples

Open computer use

Check out the example open-source app in a separate repository.

Basic SDK usage examples

Check out the examples directory for more examples on how to use the SDK:

🚀 Getting started

The E2B Desktop Sandbox is built on top of E2B Sandbox.

1. Get E2B API key

Sign up at E2B and get your API key. Set environment variable E2B_API_KEY with your API key.

2. Install SDK

pip install e2b-desktop

3. Create Desktop Sandbox

from e2b_desktop import Sandbox

# Basic initialization
desktop = Sandbox()

# With custom configuration
desktop = Sandbox(
    display=":0",  # Custom display (defaults to :0)
    resolution=(1920, 1080),  # Custom resolution
    dpi=96,  # Custom DPI
)

Features

Streaming desktop's screen

from e2b_desktop import Sandbox
desktop = Sandbox()

# Start the stream
desktop.stream.start()

# Get stream URL
url = desktop.stream.get_url()
print(url)

# Stop the stream
desktop.stream.stop()

Streaming with password protection

from e2b_desktop import Sandbox
desktop = Sandbox()

# 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()

Streaming specific application

[!WARNING]

  • Will raise an error if the desired application is not open yet
  • The stream will close once the application closes
  • Creating multiple streams at the same time is not supported, you may have to stop the current stream and start a new one for each application
from e2b_desktop import Sandbox
desktop = Sandbox()

# 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()

Mouse control

from e2b_desktop import Sandbox
desktop = Sandbox()

desktop.double_click()
desktop.left_click()
desktop.left_click(x=100, y=200)
desktop.right_click()
desktop.right_click(x=100, y=200)
desktop.middle_click()
desktop.middle_click(x=100, y=200)
desktop.scroll(10) # Scroll by the amount. Positive for up, negative for down.
desktop.move_mouse(100, 200) # Move to x, y coordinates
desktop.drag((100, 100), (200, 200)) # Drag using the mouse
desktop.mouse_press("left") # Press the mouse button
desktop.mouse_release("left") # Release the mouse button

Keyboard control

from e2b_desktop import Sandbox
desktop = Sandbox()

# Write text at the current cursor position with customizable typing speed
desktop.write("Hello, world!")  # Default: chunk_size=25, delay_in_ms=75
desktop.write("Fast typing!", chunk_size=50, delay_in_ms=25)  # Faster typing

# Press keys
desktop.press("enter")
desktop.press("space")
desktop.press("backspace")
desktop.press(["ctrl", "c"]) # Key combination

Window control

Python

from e2b_desktop import Sandbox
desktop = Sandbox()

# 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)

Screenshot

from e2b_desktop import Sandbox
desktop = Sandbox()

# Take a screenshot and save it as "screenshot.png" locally
image = desktop.screenshot()
# Save the image to a file
with open("screenshot.png", "wb") as f:
    f.write(image)

Open file

from e2b_desktop import Sandbox
desktop = Sandbox()

# Open file with default application
desktop.files.write("/home/user/index.js", "console.log('hello')") # First create the file
desktop.open("/home/user/index.js") # Then open it

Run any bash commands

from e2b_desktop import Sandbox
desktop = Sandbox()

# Run any bash command
out = desktop.commands.run("ls -la /home/user")
print(out)

Wait

from e2b_desktop import Sandbox
desktop = Sandbox()

desktop.wait(1000) # Wait for 1 second

Under the hood

The desktop-like environment is based on Linux and Xfce at the moment. We chose Xfce because it's a fast and lightweight environment that's also popular and actively supported. However, this Sandbox template is fully customizable and you can create your own desktop environment. Check out the sandbox template's code here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

e2b_desktop-1.6.5.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

e2b_desktop-1.6.5-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file e2b_desktop-1.6.5.tar.gz.

File metadata

  • Download URL: e2b_desktop-1.6.5.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.22 Linux/6.8.0-1027-azure

File hashes

Hashes for e2b_desktop-1.6.5.tar.gz
Algorithm Hash digest
SHA256 e0e015ea48d3ae74ccde0aeeba8a5a7c804f613aa0fc3e6535d07d170339a267
MD5 d2b733f47d54f33cf94dfaa08b181274
BLAKE2b-256 2db9388d6d49a5ce44ec1a2f76f4d802fc04ad7dbe71f64d97a79bd34eab90a0

See more details on using hashes here.

File details

Details for the file e2b_desktop-1.6.5-py3-none-any.whl.

File metadata

  • Download URL: e2b_desktop-1.6.5-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.22 Linux/6.8.0-1027-azure

File hashes

Hashes for e2b_desktop-1.6.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ab02d3a98d9483392f2b03c4eb3cc1f6a2df057ecc47e602eaa872d928cfbe2f
MD5 252b9c58e5d1d98f47da7da8cd3d0ac6
BLAKE2b-256 5fd5d12e6c542e17abc0976c243ac1874f65a382933963075c1c9b5272889a8c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page