Skip to content

Commit 16430b3

Browse files
committed
docs: improve Linux Desktop and Desktop Template documentation
- Add explanatory prose before code blocks per documentation standards - Fix TypeScript code block labels to use "JavaScript & TypeScript" - Add external links for sharp, SSE, noVNC, xdotool, x11vnc, and Xvfb - Fix GitHub link to point to Surf repo instead of cookbook - Add introduction and section headers to desktop template page
1 parent 2fb4a69 commit 16430b3

2 files changed

Lines changed: 36 additions & 17 deletions

File tree

docs/template/examples/desktop.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ title: "Desktop"
33
description: "Sandbox with Ubuntu Desktop and VNC access"
44
---
55

6+
This template creates a sandbox with a full Ubuntu 22.04 desktop environment, including the XFCE desktop, common applications, and VNC streaming for remote access. It's ideal for building AI agents that need to interact with graphical user interfaces.
7+
8+
The template includes:
9+
- **Ubuntu 22.04** with XFCE desktop environment
10+
- **VNC streaming** via [noVNC](https://novnc.com/) for browser-based access
11+
- **Pre-installed applications**: LibreOffice, text editors, file manager, and common utilities
12+
- **Automation tools**: [xdotool](https://github.com/jordansissel/xdotool) and scrot for programmatic desktop control
13+
14+
## Template Definition
15+
16+
The template installs the desktop environment, sets up VNC streaming via [x11vnc](https://github.com/LibVNC/x11vnc) and noVNC, and configures a startup script.
617

718
<CodeGroup>
819

@@ -131,6 +142,9 @@ template = (
131142

132143
</CodeGroup>
133144

145+
## Startup Script
146+
147+
The startup script initializes the virtual display using [Xvfb](https://www.x.org/releases/X11R7.6/doc/man/man1/Xvfb.1.xhtml) (X Virtual Framebuffer), launches the XFCE desktop session, starts the VNC server, and exposes the desktop via noVNC on port 6080. This script runs automatically when the sandbox starts.
134148

135149
```bash start_command.sh
136150
#!/bin/bash
@@ -156,6 +170,9 @@ cd /opt/noVNC/utils && ./novnc_proxy --vnc localhost:5900 --listen 6080 --web /o
156170
sleep 2
157171
```
158172

173+
## Building the Template
174+
175+
Build the template with increased CPU and memory allocation to handle the desktop environment installation. The build process may take several minutes due to the size of the packages being installed.
159176

160177
<CodeGroup>
161178

docs/use-cases/linux-desktop.mdx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ This guide is a demo version of [E2B Surf](https://github.com/e2b-dev/surf), an
3030
</CardGroup>
3131

3232
<Note>
33-
Full source code available on [GitHub](https://github.com/e2b-dev/e2b-cookbook).
33+
Full source code available on [GitHub](https://github.com/e2b-dev/surf).
3434
</Note>
3535

3636
## Project Structure
3737

38+
This starter project follows a standard Next.js App Router structure with additional directories for AI services, utilities, and type definitions. The separation keeps concerns modular and makes the codebase easy to navigate.
39+
3840
<CodeGroup>
39-
```ts TypeScript
41+
```typescript JavaScript & TypeScript
4042
surf-starter/
4143
├── app/
4244
│ ├── api/chat/
@@ -79,7 +81,7 @@ This application creates an autonomous AI loop that enables natural language con
7981
6. **Feedback Loop** - A new screenshot is taken and sent back to the AI
8082
7. **Iteration** - The loop continues until the task is complete (maximum 15 iterations)
8183

82-
All updates stream to your browser in real-time via Server-Sent Events (SSE), giving you live visibility into what the AI is thinking and doing.
84+
All updates stream to your browser in real-time via [Server-Sent Events (SSE)](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events), giving you live visibility into what the AI is thinking and doing.
8385

8486
---
8587

@@ -105,7 +107,7 @@ Initialize a new Next.js project and install the required dependencies.
105107
**Dependencies explained:**
106108
- `@e2b/desktop` - E2B Desktop SDK for controlling virtual Linux desktops
107109
- `openai` - OpenAI SDK for Computer Use API integration
108-
- `sharp` - Fast image processing library for screenshot optimization
110+
- [`sharp`](https://sharp.pixelplumbing.com/) - Fast image processing library for screenshot optimization
109111
</Step>
110112
</Steps>
111113

@@ -130,7 +132,7 @@ Set up your API keys and create environment validation utilities.
130132
<Step title="Environment Validation">
131133
Create `lib/env.ts` to validate environment variables:
132134

133-
```typescript
135+
```typescript JavaScript & TypeScript
134136
// lib/env.ts
135137
export function getEnv() {
136138
const E2B_API_KEY = process.env.E2B_API_KEY;
@@ -156,7 +158,7 @@ Define TypeScript interfaces for type safety throughout the application.
156158

157159
Create `types/index.ts` with core application types:
158160

159-
```typescript
161+
```typescript JavaScript & TypeScript
160162
// types/index.ts
161163

162164
// Message structure for chat interface
@@ -203,7 +205,7 @@ Centralize all configuration values for easy management.
203205

204206
Create `lib/constants.ts` with application-wide constants:
205207

206-
```typescript
208+
```typescript JavaScript & TypeScript
207209
// lib/constants.ts
208210

209211
// Sandbox configuration
@@ -248,7 +250,7 @@ Build helper functions for screenshot processing, streaming, and action executio
248250
<Step title="Screenshot Processing">
249251
Create `lib/utils/screenshot.ts` to optimize screenshots:
250252

251-
```typescript
253+
```typescript JavaScript & TypeScript
252254
// lib/utils/screenshot.ts
253255
import sharp from 'sharp';
254256
import { SCREENSHOT_CONFIG } from '@/lib/constants';
@@ -274,7 +276,7 @@ Build helper functions for screenshot processing, streaming, and action executio
274276
<Step title="Safe Stream Controller">
275277
Create `lib/utils/stream.ts` for SSE streaming:
276278

277-
```typescript
279+
```typescript JavaScript & TypeScript
278280
// lib/utils/stream.ts
279281
export function createSafeStreamController(
280282
controller: ReadableStreamDefaultController
@@ -316,7 +318,7 @@ Build helper functions for screenshot processing, streaming, and action executio
316318
<Step title="Action Execution">
317319
Create `lib/utils/actions.ts` to map AI actions to E2B SDK calls:
318320

319-
```typescript
321+
```typescript JavaScript & TypeScript
320322
// lib/utils/actions.ts
321323
import type { Sandbox } from '@e2b/desktop';
322324
import type { ComputerAction } from '@/types';
@@ -389,7 +391,7 @@ Define the system instructions that guide the AI agent's behavior.
389391

390392
Create `lib/ai/instructions.ts` with the AI agent prompt:
391393

392-
```typescript
394+
```typescript JavaScript & TypeScript
393395
// lib/ai/instructions.ts
394396
export const SYSTEM_INSTRUCTIONS = `You are Surf, an AI assistant that controls a Linux desktop to help users with tasks.
395397
@@ -436,7 +438,7 @@ Implement the core AI execution loop that powers desktop control.
436438

437439
Create `lib/services/openai.ts` with the computer use loop:
438440

439-
```typescript
441+
```typescript JavaScript & TypeScript
440442
// lib/services/openai.ts
441443
import OpenAI from 'openai';
442444
import type { Sandbox } from '@e2b/desktop';
@@ -558,7 +560,7 @@ Create the backend API endpoint that orchestrates sandbox creation and AI execut
558560

559561
Create `app/api/chat/route.ts` for the SSE streaming endpoint:
560562

561-
```typescript
563+
```typescript JavaScript & TypeScript
562564
// app/api/chat/route.ts
563565
import { Sandbox } from '@e2b/desktop';
564566
import { NextRequest } from 'next/server';
@@ -666,7 +668,7 @@ Add Next.js server actions for sandbox management from the client.
666668

667669
Create `app/actions.ts` for server-side operations:
668670

669-
```typescript
671+
```typescript JavaScript & TypeScript
670672
// app/actions.ts
671673
'use server';
672674

@@ -722,7 +724,7 @@ These server actions allow the client to:
722724
Create `app/page.tsx` with a chat interface, real-time status tracking, VNC viewer, and countdown timer with timeout management.
723725

724726
<Accordion title="View complete app/page.tsx implementation">
725-
```typescript
727+
```typescript JavaScript & TypeScript
726728
'use client';
727729

728730
import { useState, useRef, useEffect, useCallback } from 'react';
@@ -1763,7 +1765,7 @@ Create `styles/globals.css` with E2B branding, animations, and responsive design
17631765

17641766
Create `app/layout.tsx` to import the global styles and configure metadata.
17651767

1766-
```typescript
1768+
```typescript JavaScript & TypeScript
17671769
// app/layout.tsx
17681770
import type { Metadata } from 'next';
17691771
import '../styles/globals.css';
@@ -1846,7 +1848,7 @@ Start the development server and test your AI desktop control application.
18461848

18471849
<Accordion title="Screenshot quality issues">
18481850
Adjust the screenshot dimensions in `lib/constants.ts`:
1849-
```typescript
1851+
```typescript JavaScript & TypeScript
18501852
export const SCREENSHOT_CONFIG = {
18511853
MAX_WIDTH: 1280, // Increase for better quality
18521854
MAX_HEIGHT: 960, // Increase for better quality

0 commit comments

Comments
 (0)