A Next.js application that allows AI to interact with a virtual desktop environment. This project integrates E2B's desktop sandbox with OpenAI's API to create an AI agent that can perform tasks on a virtual computer through natural language instructions.
E2B is an open source isolated virtual computer in the cloud made for AI use cases.
The Computer Use App provides a web interface where users can:
- Start a virtual desktop sandbox environment
- Send natural language instructions to an AI agent
- Watch as the AI agent performs actions on the virtual desktop
- Interact with the AI through a chat interface
The application uses Server-Sent Events (SSE) to stream AI responses and actions in real-time, providing a seamless experience.
The application consists of several key components:
- Frontend UI (Next.js): Provides the user interface with a virtual desktop view and chat interface
- E2B Desktop Sandbox: Creates and manages virtual desktop environments
- OpenAI Computer Use: Processes user instructions and generates actions for the AI agent
- Streaming API: Handles real-time communication between the frontend and backend
- User starts a new sandbox instance
- E2B creates a virtual desktop and provides a URL for streaming
- User sends instructions via the chat interface
- Backend processes the instructions using OpenAI's API
- AI generates actions (clicks, typing, etc.) to perform on the virtual desktop
- Actions are executed on the sandbox and streamed back to the frontend
- The process repeats as the user continues to provide instructions
Before starting, you'll need:
- Node.js (version specified in package.json)
- npm (comes with Node.js)
- An E2B API key
- An OpenAI API key
- Clone the repository
git clone https://github.com/e2b-dev/surf
cd surf
- Install dependencies
npm install
- Set up environment variables
Create a .env.local
file in the root directory based on the provided .env.example
:
E2B_API_KEY=your_e2b_api_key
OPENAI_API_KEY=your_openai_api_key
- Start the development server
npm run dev
- Open the application
Navigate to http://localhost:3000 in your browser.
-
Start a Sandbox Instance
- Click the "Start new Sandbox" button to initialize a virtual desktop environment
- Wait for the sandbox to start (this may take a few seconds)
-
Send Instructions
- Type your instructions in the chat input (e.g., "Open Firefox and go to google.com")
- Press Enter or click the send button
- You can also select from example prompts if available
-
Watch AI Actions
- The AI will process your instructions and perform actions on the virtual desktop
- You can see the AI's reasoning and actions in the chat interface
- The virtual desktop will update in real-time as actions are performed
-
Manage the Sandbox
- The timer shows the remaining time for your sandbox instance
- You can stop the sandbox at any time by clicking the "Stop" button
- The sandbox will automatically extend its time when it's about to expire
- Virtual Desktop Environment: Runs a Linux-based desktop in a sandbox
- AI-Powered Interaction: Uses OpenAI's API to understand and execute user instructions
- Real-Time Streaming: Shows AI actions and responses as they happen
- Chat Interface: Provides a conversational interface for interacting with the AI
- Example Prompts: Offers pre-defined instructions to help users get started
- Dark/Light Mode: Supports both dark and light themes
The application uses several key dependencies:
- Next.js: React framework for the frontend
- @e2b/desktop: SDK for creating and managing desktop sandbox environments
- OpenAI: SDK for interacting with OpenAI's API
- Tailwind CSS: Utility-first CSS framework for styling
- Framer Motion: Library for animations
See package.json
for a complete list of dependencies.
- /api/chat: Handles chat messages and streams AI responses and actions
- createSandbox: Creates a new sandbox instance
- increaseTimeout: Extends the sandbox timeout
- stopSandboxAction: Stops a running sandbox instance
- Sandbox not starting: Verify your E2B API key is correct in
.env.local
- AI not responding: Check that your OpenAI API key is valid and has access to the required models
- Actions not working: Ensure the sandbox is running and the AI has proper instructions
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the E2B Documentation
- Join the E2B Discord
- Open an issue