CoolFace
Apppublic

nimesh24/computer-use-agent

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
App README

Computer Use Agent ๐Ÿค–

An AI autonomous agent powered by Google Gemini 2.5 and Playwright. It browses the web, extracts information, and saves summaries to local files, all while operating within a secure, sandboxed environment.

Now features a Streamlit Web Interface for easy interaction and Docker support for cloud deployment.

๐ŸŒŸ Features

  • โ€”๐Ÿง  AI-Powered Browsing: Uses Gemini 2.5's computer use capabilities to navigate websites and interact with elements.
  • โ€”๐Ÿ›ก๏ธ Secure by Design: Custom "Security Kernel" (security.py) prevents prompt injection, restricts browsing to allowed domains (Wikipedia), and sandboxes file access.
  • โ€”๐Ÿ’ป Dual Interface:
  • โ€”Web UI: User-friendly dashboard built with Streamlit.
  • โ€”CLI: Direct terminal access for power users.
  • โ€”๐Ÿณ Docker Ready: Containerized environment for safe and easy deployment to Hugging Face Spaces or any cloud provider.
  • โ€”๐Ÿ“„ Automatic Summarization: Reads articles and creates structured text summaries in a designated output folder.

๐Ÿ“‚ Project Structure

text
computer-use-agent/
โ”œโ”€โ”€ app.py           # ๐Ÿ–ฅ๏ธ Streamlit Web Interface (Entry Point)
โ”œโ”€โ”€ agent.py         # ๐Ÿง  Main Agent Logic (Gemini + Playwright)
โ”œโ”€โ”€ security.py      # ๐Ÿ”’ Security Guardrails (Policy Enforcement)
โ”œโ”€โ”€ Dockerfile       # ๐Ÿณ Container configuration
โ”œโ”€โ”€ requirements.txt # ๐Ÿ“ฆ Python dependencies
โ”œโ”€โ”€ .env             # ๐Ÿ”‘ API Keys (Optional)
โ””โ”€โ”€ runs/            # ๐Ÿ“‚ Output folder for generated files

๐Ÿš€ Quick Start

Prerequisites

Option 1: Run with Docker (Recommended)

This method guarantees the browser installs correctly without messing up your local machine.

  1. 1.Build the Container:
bash
docker build -t browser-agent .
  1. 1.Run the App:
bash
docker run -p 8501:8501 browser-agent
  1. 1.Open Browser: Go to http://localhost:8501

Option 2: Run Locally

  1. 1.Clone & Install:
bash
git clone https://github.com/yourusername/computer-use-agent.git
cd computer-use-agent

pip install -r requirements.txt
playwright install chromium
  1. 1.Start the Web UI:
bash
streamlit run app.py
  1. 1.Start via CLI (Alternative):
bash
# Set key first: export GOOGLE_API_KEY=AIzaSy...
python agent.py "Find information about Apollo 11"

๐Ÿ”’ Security Architecture

This project implements a Policy Enforcement Point (PEP) pattern in security.py to ensure the AI behaves safely.

GuardrailFunctionDescription
Input Sanitizationvalidate_goal()Blocks malicious keywords (e.g., rm -rf, /etc/passwd) and limits prompt length.
Domain Allowlistvalidate_url()SSRF Protection. The agent is strictly limited to browsing *.wikipedia.org. It cannot access local networks or malicious sites.
File Sandboxvalidate_file_path()Path Traversal Protection. Files can ONLY be written to the ./runs directory.

๐Ÿ› ๏ธ Configuration

You can configure the agent via the Web UI sidebar or by setting environment variables in a .env file.

VariableDescriptionDefault
GOOGLE_API_KEYYour Gemini API KeyRequired
HEADLESSRun browser without UI (faster)true
SCREEN_WIDTHBrowser viewport width1440
SCREEN_HEIGHTBrowser viewport height900
MAX_TURNSMaximum actions per run8

โ˜๏ธ Deployment

Deploy to Hugging Face Spaces

  1. 1.Create a new Space on Hugging Face.
  2. 2.Select Docker as the SDK.
  3. 3.Upload all project files (Dockerfile, app.py, etc.).
  4. 4.Hugging Face will automatically build and launch your agent!

๐Ÿ“ License

This project is open-source.

Author: Sachintha Dissanayaka