Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fruity-zoos-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@e2b/desktop-python': patch
'@e2b/desktop': patch
---

fix overwriting .vnc directory when stream is re-started
63 changes: 49 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ Each sandbox is isolated from the others and can be customized with any dependen

## Examples

**Basic SDK Examples**
**SDK Examples**

- Check out the examples directory for more examples on how to use the SDK:
- Basic Examples:
- [Python](./examples/basic-python)
- [JavaScript](./examples/basic-javascript)
- Streaming Desktop Applications:
- [Python](./examples/streaming-apps-python)
- [JavaScript](./examples/streaming-apps-javascript)

**[Open Computer Use](https://github.com/e2b-dev/open-computer-use)**

Expand Down Expand Up @@ -52,31 +55,63 @@ npm install @e2b/desktop
```python
from e2b_desktop import Sandbox

# Basic initialization
# Create a new desktop sandbox
desktop = Sandbox()

# With custom configuration
desktop = Sandbox(
display=":0", # Custom display (defaults to :0)
resolution=(1920, 1080), # Custom resolution
dpi=96, # Custom DPI
# 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()
```

**JavaScript**

```javascript
import { Sandbox } from '@e2b/desktop'

// Basic initialization
// Start a new desktop sandbox
const desktop = await Sandbox.create()

// With custom configuration
const desktop = await Sandbox.create({
display: ':0', // Custom display (defaults to :0)
resolution: [1920, 1080], // Custom resolution
dpi: 96, // Custom DPI
// 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()
```

## Features
Expand Down
92 changes: 92 additions & 0 deletions examples/streaming-apps-javascript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Streaming Applications Example

Streaming applications is a feature of the E2B Desktop Sandbox.

> [!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

## How to run

### 1. Get E2B API key

Sign up at [E2B](https://e2b.dev) and get your API key.
Set environment variable `E2B_API_KEY` with your API key.

### 2. Install SDK

```bash
npm install @e2b/desktop
```

### 3. Create Desktop Sandbox

```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 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
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 10s for the application to open
await desktop.wait(10000)

// 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()
```
92 changes: 92 additions & 0 deletions examples/streaming-apps-python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Streaming Applications Example

Streaming applications is a feature of the E2B Desktop Sandbox.

> [!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

## How to run

### 1. Get E2B API key

Sign up at [E2B](https://e2b.dev) and get your API key.
Set environment variable `E2B_API_KEY` with your API key.

### 2. Install SDK

```bash
pip install e2b-desktop
```

### 3. Create Desktop Sandbox

```python
from e2b_desktop import Sandbox

# Create a new desktop sandbox
desktop = Sandbox()
print('Desktop sandbox created', desktop.sandbox_id)

# Launch an application
print('Launching Google Chrome')
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
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 10s for the application to open
desktop.wait(10000)

# 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()
```
28 changes: 22 additions & 6 deletions packages/js-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,31 @@ npm install @e2b/desktop
```javascript
import { Sandbox } from '@e2b/desktop'

// Basic initialization
// Start a new desktop sandbox
const desktop = await Sandbox.create()

// With custom configuration
const desktop = await Sandbox.create({
display: ':0', // Custom display (defaults to :0)
resolution: [1920, 1080], // Custom resolution
dpi: 96, // Custom DPI
// 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()
```

## Features
Expand Down
3 changes: 2 additions & 1 deletion packages/js-sdk/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ class VNCServer {
private async getVNCCommand(windowId?: string): Promise<string> {
let pwdFlag = '-nopw'
if (this.novncAuthEnabled) {
await this.desktop.commands.run('mkdir ~/.vnc')
// Create .vnc directory if it doesn't exist
await this.desktop.commands.run('mkdir -p ~/.vnc')
await this.desktop.commands.run(
`x11vnc -storepasswd ${this.password} ~/.vnc/passwd`
)
Expand Down
28 changes: 22 additions & 6 deletions packages/python-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,31 @@ pip install e2b-desktop
```python
from e2b_desktop import Sandbox

# Basic initialization
# Create a new desktop sandbox
desktop = Sandbox()

# With custom configuration
desktop = Sandbox(
display=":0", # Custom display (defaults to :0)
resolution=(1920, 1080), # Custom resolution
dpi=96, # Custom DPI
# 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()
```

## Features
Expand Down
2 changes: 1 addition & 1 deletion packages/python-sdk/e2b_desktop/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def start(self, vnc_port: Optional[int] = None, port: Optional[int] = None, requ
# Set up VNC command
pwd_flag = "-nopw"
if self._novnc_auth_enabled:
self.__desktop.commands.run("mkdir ~/.vnc")
self.__desktop.commands.run("mkdir -p ~/.vnc")
self.__desktop.commands.run(f"x11vnc -storepasswd {self._novnc_password} ~/.vnc/passwd")
pwd_flag = "-usepw"

Expand Down