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/witty-buttons-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@e2b/desktop-python': patch
'@e2b/desktop': patch
---

added gtk-launch and launch SDK method
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,29 @@ await desktop.files.write('/home/user/index.js', "console.log('hello')") // Firs
await desktop.open('/home/user/index.js') // Then open it
```

### Launch applications

**Python**

```python
from e2b_desktop import Sandbox
desktop = Sandbox()

# Launch the application
desktop.launch('google-chrome')
```

**JavaScript**

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

const desktop = await Sandbox.create()

// Launch the application
await desktop.launch('google-chrome')
```

### Run any bash commands

**Python**
Expand Down
11 changes: 11 additions & 0 deletions packages/js-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ await desktop.files.write('/home/user/index.js', "console.log('hello')") // Firs
await desktop.open('/home/user/index.js') // Then open it
```

### Launch applications

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

const desktop = await Sandbox.create()

// Launch the application
await desktop.launch('google-chrome')
```

### Run any bash commands

```javascript
Expand Down
12 changes: 12 additions & 0 deletions packages/js-sdk/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,18 @@ export class Sandbox extends SandboxBase {

return result.stdout.trim()
}

/**
* Launch an application.
* @param application - The application to launch.
* @param uri - The URI to open in the application.
*/
async launch(application: string, uri?: string): Promise<void> {
await this.commands.run(`gtk-launch ${application} ${uri ?? ''}`, {
background: true,
timeoutMs: 0,
})
}
}

interface VNCServerOptions {
Expand Down
12 changes: 10 additions & 2 deletions packages/python-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ desktop.press(["ctrl", "c"]) # Key combination

### Window control

**Python**

```python
from e2b_desktop import Sandbox
desktop = Sandbox()
Expand Down Expand Up @@ -195,6 +193,16 @@ desktop.files.write("/home/user/index.js", "console.log('hello')") # First creat
desktop.open("/home/user/index.js") # Then open it
```

### Launch applications

```python
from e2b_desktop import Sandbox
desktop = Sandbox()

# Launch the application
desktop.launch('google-chrome')
```

### Run any bash commands

```python
Expand Down
6 changes: 6 additions & 0 deletions packages/python-sdk/e2b_desktop/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,9 @@ def get_window_title(self, window_id: str) -> str:
Get the title of the window with the given ID.
"""
return self.commands.run(f"xdotool getwindowname {window_id}").stdout.strip()

def launch(self, application: str, uri: Optional[str] = None):
"""
Launch an application.
"""
self.commands.run(f"gtk-launch {application} {uri or ''}", background=True, timeout=0)
4 changes: 4 additions & 0 deletions template/e2b.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ COPY ./wallpaper.png /usr/share/backgrounds/xfce/wallpaper.png
RUN mkdir -p /home/user/.config/xfce4/xfconf/xfce-perchannel-xml/
COPY ./xfce4-desktop.xml /home/user/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml

# Install gtk-launch and update desktop database
RUN apt-get install -y libgtk-3-bin && \
update-desktop-database /usr/share/applications/

# Copy firefox policies
COPY firefox-policies.json /usr/lib/firefox-esr/distribution/policies.json
COPY firefox-autoconfig.js /usr/lib/firefox-esr/defaults/pref/autoconfig.js
Expand Down