Steel Browser Use Example
This example demonstrates how to integrate Steel with the browser-use framework to create an AI agent capable of interacting with web browsers. It leverages Steel's session management to provide a secure, cloud-based browser instance for browser-use to connect to.
Features
- Seamless integration between Steel and browser-use
- Cloud-based browser automation with Steel sessions
- AI-powered browser interaction using OpenAI GPT-4
- Automatic cleanup of resources
- Robust error handling and session management
Prerequisites
- Python 3.11 or higher
- Python package manager (Recommended
uv:pip install uv) - Steel API key (Get 100 free browser hours here.)
- OpenAI API key
Installation
-
Clone the repository:
git clone https://github.com/steel-dev/steel-cookbook.git cd steel-cookbook/examples/steel-browser-use-starter -
Create and activate a virtual environment with venv:
python -m venv .venv source .venv/bin/activate # On Windows, use: .venv\Scripts\activate -
Install the required dependencies using venv:
pip install .Note: We're using venv to manage our environment and pip to install the packages. This ensures all dependencies are resolved consistently using pip's dependency resolution. If you're having issue with speed or dependencies, feel free to switch back to python/pip and try these steps again.
-
Copy the environment variables file and configure your API keys:
cp .env.example .env -
Edit the
.envfile and add your API keys:STEEL_API_KEY=your_steel_api_key_here OPENAI_API_KEY=your_openai_api_key_here
Usage
Run the example with:
python main.py
The script will:
- Create a new Steel session
- Connect browser-use to the Steel session using the WebSocket URL
- Execute the AI agent's task (e.g., summarizing the Steel Docs changelog)
- Automatically clean up resources when done
How It Works
-
Session Creation: The script creates a Steel session with optional proxy and CAPTCHA-solving capabilities.
-
Browser Integration: The WebSocket URL from the Steel session is passed to browser-use's Browser configuration.
-
AI Agent Setup: A browser-use Agent is created with:
- The specified task
- OpenAI GPT-4 language model
- Browser instance connected to Steel
-
Execution: The agent runs autonomously, performing the specified task.
-
Cleanup: Resources are properly released, including:
- Closing the browser connection process
- Releasing the Steel session
Error Handling
The example includes comprehensive error handling:
- Validation of required environment variables
- Try/except blocks for session management
- Proper cleanup in case of failures
- Informative error messages
Customization
You can modify the example by:
- Changing the task in
main.py - Adjusting Steel session parameters
- Configuring different browser-use settings
- Using a different OpenAI model or adjusting model parameters
Contributing
Feel free to submit issues, fork the repository, and create pull requests for any improvements.
License
This example is part of the Steel Cookbook and is licensed under the MIT License. See the LICENSE file for details.