Open Computer Use

repository·master·Indexed 24 days ago

https://github.com/e2b-dev/open-computer-use

A secure, cloud-based Linux computer environment powered by E2B Desktop Sandboxes. It allows open-source and proprietary LLMs to control a computer via keyboard, mouse, and shell commands. The system supports multiple model roles—grounding, vision, and action—with integrations for providers including OpenAI, Anthropic, Groq, Gemini, Mistral, and OS-Atlas.

Tokens
4.5K
Snippets
5
Records
33
Agent score
79%

What's inside Open Computer Use

  1. Install Open Computer Use

    master

    To set up Open Computer Use, follow these steps to install prerequisites, clone the repository, and configure your environment.

    1. Install Prerequisites

    Ensure you have Python 3.10+ and git installed. Use Homebrew to install poetry and ffmpeg:

    brew install poetry ffmpeg

    2. Clone the Repository

    git clone https://github.com/e2b-dev/open-computer-use/
    cd open-computer-use

    3. Configure Environment Variables

    Create a .env file in the open-computer-use directory. You must provide an E2B_API_KEY and the API keys for your chosen LLM providers.

    # Required for the E2B Desktop Sandbox
    E2B_API_KEY="your-e2b-api-key"
    
    # Provider-specific keys (add only what you use in config.py)
    FIREWORKS_API_KEY=...
    OPENROUTER_API_KEY=...
    LLAMA_API_KEY=...
    GROQ_API_KEY=...
    GEMINI_API_KEY=...
    OPENAI_API_KEY=...
    ANTHROPIC_API_KEY=...
    MOONSHOT_API_KEY=...
    
    # Required to bypass Gradio rate limits for Hugging Face Spaces
    HF_TOKEN=...
    brew install poetry ffmpeg
    git clone https://github.com/e2b-dev/open-computer-use/
    cd open-computer-use
  2. Run the Open Computer Use agent

    master

    After setting up your environment, use poetry to install dependencies and start the web interface.

    Standard Start

    This will start the agent and prompt you for instructions in the web interface:

    poetry install
    poetry run start

    Start with an initial prompt

    You can pass a specific instruction immediately using the --prompt flag:

    poetry run start --prompt "use the web browser to get the current weather in sf"

    The display stream of the sandbox should become visible a few seconds after the program starts.

    poetry install
    poetry run start --prompt "use the web browser to get the current weather in sf"
  3. Implement tool use with LLM providers

    master

    To enable tool use, pass a functions dictionary to the call method. The dictionary should follow this structure:

    functions = {
        "function_name": {
            "description": "A description of what the tool does",
            "params": {
                "param_name": "Description of the parameter"
            }
        }
    }

    When the model decides to use a tool, the call method returns a list of tool call objects. Each object contains:

    • type: "function"
    • name: The name of the tool
    • parameters: A dictionary of the arguments provided by the model.
  4. How SandboxAgent handles UI interaction and grounding

    master

    When the agent needs to interact with a specific UI element (via click, double_click, or right_click), it follows a grounding workflow:

    1. Screenshot: It captures the current screen.
    2. Grounding: It calls a grounding_model with the user's query and the screenshot to find the (x, y) coordinates.
    3. Visualization: It draws a large dot on the screenshot at the target position and saves it for logging.
    4. Action: It moves the mouse to the coordinates and executes the requested click command (e.g., self.sandbox.left_click).
  5. Configure LLM providers in config.py

    master

    Open Computer Use allows you to swap LLMs for different tasks. The agent uses three distinct model roles: grounding_model, vision_model, and action_model. These are configured in os_computer_use/config.py using providers imported from providers.py.

    Supported Model Roles

    • grounding_model: Used for spatial reasoning and grounding.
    • vision_model: Used for visual perception.
    • action_model: Used for determining the next computer actions.

    Example Configuration

    grounding_model = providers.OSAtlasProvider()
    vision_model = providers.GroqProvider("llama3.2")
    action_model = providers.GroqProvider("llama3.3")

    Supported Providers

    • Fireworks, OpenRouter, Llama API: Llama 3.2 (vision), Llama 3.3 (action).
    • Groq: Llama 3.2 (vision + action), Llama 3.3 (action).
    • DeepSeek: DeepSeek (action).
    • Google: Gemini 2.0 Flash (vision + action).
    • OpenAI: GPT-4o and GPT-4o mini (vision + action).
    • Anthropic: Claude (vision + action).
    • HuggingFace Spaces: OS-Atlas (grounding), ShowUI (grounding).
    • Mistral AI: Pixtral (vision), Mistral Large (actions).
    • Others: Moonshot.
  6. Configure E2B API Key

    master

    The application requires an E2B API key to function. This should be set as an environment variable.

    Environment Variable:

    • E2B_API_KEY: Your E2B API key.

    You can provide this in a .env file, which is automatically loaded by the application.

  7. Available model providers in os_computer_use

    master
    The following provider classes are available in os_computer_use.providers to configure the agent's models. Most providers require a model name string as a positional argument.
  8. Configure model providers in config.py

    master

    The agent requires three specific model assignments to function: a grounding_model, a vision_model, and an action_model. These are instantiated using classes from the os_computer_use.providers module.

    • grounding_model: Used for grounding tasks. Available providers include OSAtlasProvider and ShowUIProvider.
    • vision_model: Used for visual processing. Supported providers include FireworksProvider, OpenAIProvider, AnthropicProvider, MoonshotProvider, GroqProvider, and OpenRouterProvider.
    • action_model: Used for executing actions. Supported providers include FireworksProvider, OpenAIProvider, AnthropicProvider, MoonshotProvider, MistralProvider, and GroqProvider.

    When selecting a provider, you must pass the specific model identifier (e.g., `

  9. Use the Browser class to control webview windows

    master

    The Browser class provides an interface to open and close a webview window in a separate process. This allows for non-blocking browser interaction.

    Key methods:

    • open(url, width=None, height=None): Launches a new browser window at the specified URL. You can optionally provide width and height (defaults to 1024x768).
    • close(): Sends a close command to the webview process and waits for it to terminate.
  10. Execute tasks with SandboxAgent.run()

    master

    The run(instruction) method is the main entrypoint to start an autonomous computer-use session. It takes a natural language instruction representing the goal.

    Workflow:

    1. Appends the objective to the agent's message history.
    2. Enters a loop where it uses an action_model to decide on tool calls.
    3. Uses a vision_model to analyze screenshots of the current state.
    4. Executes requested tools (like click, type_text, or run_command) via the sandbox.
    5. Continues until the model calls the stop tool or the loop terminates.

    Note: The method automatically sets the sandbox timeout to 60 seconds during the loop to prevent idle timeouts.

  11. Extend SandboxAgent with custom tools

    master

    You can add new capabilities to the SandboxAgent by using the @tool decorator on methods within the class. The decorator registers the method's name, description, and parameters into the tools dictionary used by the LLM.

    Example:

    @tool(description="Custom tool description", params={"arg": "arg description"})
    def my_custom_tool(self, arg):
        # implementation
        return "result"
  12. OpenAIBaseProvider implementation details

    master

    The OpenAIBaseProvider uses the OpenAI Python SDK. It supports:

    • Image handling: Automatically detects image types (e.g., PNG, JPEG) using Pillow and encodes them as Base64 data URLs.
    • Tool parsing: Includes a fallback mechanism using regex to manually parse JSON tool calls if the provider returns them as unparsed text in the message content.