CoolFace
Apppublic

iluksic/computer-use-sandbox

sourceHugging Faceapache-2.0updated 8mo agoView on Hugging Face
0likes
App README

Computer Use Agent

Implementation of Anthropic's Computer Use API with Daytona sandboxes. Enables Claude to autonomously control remote computer environments for browser automation, shell execution, file operations, and multi-step tasks.

Table of Contents

Features

Core Capabilities:

  • Computer Control - Mouse, keyboard, screenshots via Anthropic's Computer Use API (2025-01-24 beta)
  • Browser Automation - Navigate websites, interact with elements, extract data
  • Shell Execution - Run commands and scripts in sandboxed Linux environment
  • File Operations - Read, write, manage files and directories
  • Secure Isolation - All operations in Daytona's isolated sandboxes with network controls

Prerequisites

Required API Keys:

  1. 1.Anthropic - Sign up at console.anthropic.com
  2. 2.Format: sk-ant-xxxxx...
  1. 1.Daytona - Sign up at app.daytona.io
  2. 2.Format: dtn_xxxxx...
  3. 3.Requires Tier 3+ for network access

Installation

bash
# Clone repository
git clone https://github.com/your-username/computer-use-agent.git
cd computer-use-agent

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Verify installation
python -c "import anthropic, daytona, gradio; print('Success!')"

Quick Start

Web Interface (Recommended)

bash
python gradio_demo.py

Then:

  1. 1.Open http://localhost:7860
  2. 2.Enter API keys (stored in browser session only)
  3. 3.Enter task description
  4. 4.Click "Run Task"

Command Line

bash
export ANTHROPIC_API_KEY='sk-ant-your-key'
export DAYTONA_API_KEY='dtn_your-key'

python main.py "Search GitHub for popular Python repos and summarize top 3"

Python API

python
from computers.daytona import DaytonaComputer
from computers.config import DaytonaConfig
from claude_agent import ClaudeAgent

config = DaytonaConfig()
config.anthropic_api_key = "sk-ant-your-key"
config.daytona_api_key = "dtn_your-key"

with DaytonaComputer(config=config) as computer:
    agent = ClaudeAgent(
        computer=computer,
        query="Navigate to Wikipedia and find Tokyo's population",
        config=config
    )
    agent.agent_loop()
    print(agent.final_response)

Configuration

Key Configuration Options

python
from computers.config import DaytonaConfig

config = DaytonaConfig()

# Model selection
config.claude.model = "claude-sonnet-4-5"  # or opus-4-5, haiku-4-5

# Token optimization
config.claude.max_screenshots_in_history = 0  # Save tokens
config.claude.max_messages_in_history = 20    # Keep last N messages

# Network controls
config.network.block_all = False
config.network.allow_list = "0.0.0.0/0"  # Or specific CIDR ranges

# Sandbox lifecycle
config.sandbox.auto_stop_interval = 30  # Minutes

# Screen size
config.screen.width = 1024
config.screen.height = 768

Environment Variables

bash
# API Keys
export ANTHROPIC_API_KEY='sk-ant-...'
export DAYTONA_API_KEY='dtn_...'

# Optional overrides
export CLAUDE_MODEL='claude-sonnet-4-5'
export DAYTONA_SCREEN_WIDTH=1920
export DAYTONA_SCREEN_HEIGHT=1080
export DAYTONA_AUTO_STOP=60

Available Tools

The agent has access to:

Computer Control:

  • Screenshot, mouse (move, click, drag), keyboard, scroll, wait

Shell & Commands:

  • Execute commands, run scripts

File Operations:

  • Read/write files, list directories

Code Execution:

  • Run Python, JavaScript, Bash

Browser:

  • Navigate, back/forward navigation

Deployment

HuggingFace Spaces

bash
# Deploy to HuggingFace Spaces
cp app.py your-space/
cp -r computers/ claude_agent.py gradio_demo.py requirements.txt your-space/

# Push to HuggingFace
cd your-space
git add .
git commit -m "Deploy Computer Use Agent"
git push

Note: Users provide their own API keys via the web interface. Keys are session-only, never persisted.

Docker

dockerfile
FROM python:3.11-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .
EXPOSE 7860

CMD ["python", "gradio_demo.py"]
bash
docker build -t computer-use-agent .
docker run -p 7860:7860 computer-use-agent

API Reference

ClaudeAgent

python
agent = ClaudeAgent(
    computer: Computer,           # DaytonaComputer instance
    query: str,                   # Task description
    model: str = "claude-sonnet-4-5",
    verbose: bool = True,
    max_screenshots_in_history: int = 0,
    config: Optional[DaytonaConfig] = None
)

# Run agent loop
agent.agent_loop()

# Get results
result = agent.final_response
stats = agent.get_usage_stats()  # Returns token counts, API calls

DaytonaComputer

python
computer = DaytonaComputer(
    screen_size: tuple = (1024, 768),
    initial_url: str = "https://www.google.com",
    network_block_all: bool = False,
    network_allow_list: str = "0.0.0.0/0",
    config: Optional[DaytonaConfig] = None
)

# Use as context manager
with computer:
    # GUI operations
    computer.click_at(x, y)
    computer.type_text_at(x, y, "text")
    computer.navigate("https://example.com")

    # Shell operations
    result = computer.exec_command("ls -la")

    # File operations
    content = computer.read_file("/path/file.txt")
    computer.write_file("/path/file.txt", "content")

    # Code execution
    result = computer.run_python("print('hello')")

DaytonaConfig

python
# Create from environment
config = DaytonaConfig.from_env()

# Validate configuration
errors = config.validate()  # Returns list of errors

# Access sub-configs
config.claude.model
config.screen.width
config.network.block_all
config.timing.action_delay

Testing

The project includes tests covering critical components:

bash
# Run all tests
pytest tests/

# Run with verbose output
pytest tests/ -v

# Run specific test file
pytest tests/test_claude_agent.py

# Run with coverage
pytest tests/ --cov=. --cov-report=html

Test Coverage:

  • test_claude_agent.py - Agent logic, API integration, rate limiting, tools
  • test_config.py - Configuration validation and environment loading
  • test_daytona.py - Sandbox lifecycle and computer operations
  • test_gradio_demo.py - API key validation and UI formatting

License

Apache License 2.0 - see LICENSE file for details.

Copyright 2025

Licensed under the Apache License, Version 2.0. You may obtain a copy at http://www.apache.org/licenses/LICENSE-2.0

See NOTICE file for attribution information.

Resources