Skip to content

Commit 675aaa9

Browse files
DX-3089, DX-3107: Browser Use on Box: connect page section and scheduled agent guide (#879)
1 parent e0eef6b commit 675aaa9

6 files changed

Lines changed: 370 additions & 4 deletions

File tree

‎box/guides/browser-use.mdx‎

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
---
2+
title: "Scheduled Browser Use Agent"
3+
---
4+
5+
Run a [Browser Use](https://browser-use.com) agent inside Upstash Box. The agent, the browser, and the files it writes all live in one box, and a schedule runs it again on a cron.
6+
7+
This guide builds an agent that reads Hacker News every morning and saves a report to the box.
8+
9+
---
10+
11+
## 1. Set up
12+
13+
- A **Box API key** from the [Upstash Console](https://console.upstash.com/box).
14+
- An **Anthropic API key** from [API keys](https://platform.claude.com/settings/keys).
15+
16+
```bash
17+
export UPSTASH_BOX_API_KEY=box_xxxxxxxxxxxxxxxxxxxxxxxx
18+
export ANTHROPIC_API_KEY=sk-ant-api03-xxxxxxxxxxxx
19+
```
20+
21+
```bash
22+
pip install upstash-box
23+
```
24+
25+
---
26+
27+
## 2. Write the agent
28+
29+
This file runs inside the box. It starts the box's Chromium, runs the task, and writes the result to `reports/`.
30+
31+
```python title="agent.py"
32+
import asyncio
33+
from datetime import datetime, timezone
34+
from pathlib import Path
35+
36+
from browser_use import Agent, Browser, ChatAnthropic
37+
38+
TASK = """
39+
Go to news.ycombinator.com and find the first 3 stories about AI on the front page.
40+
Return a markdown list with the title, link, and points of each.
41+
Open only the first one and add a two-sentence summary of it.
42+
"""
43+
44+
45+
async def main():
46+
agent = Agent(
47+
task=TASK,
48+
llm=ChatAnthropic(model="claude-sonnet-4-5"),
49+
browser=Browser(
50+
executable_path="/usr/bin/chromium",
51+
headless=True,
52+
chromium_sandbox=False,
53+
),
54+
)
55+
history = await agent.run(max_steps=15)
56+
if not history.is_successful():
57+
raise SystemExit("The agent did not finish the task")
58+
59+
name = datetime.now(timezone.utc).strftime("%Y-%m-%d-%H%M")
60+
report = Path("/workspace/home/reports") / f"{name}.md"
61+
report.parent.mkdir(exist_ok=True)
62+
report.write_text(history.final_result())
63+
64+
65+
asyncio.run(main())
66+
```
67+
68+
---
69+
70+
## 3. Set up the box
71+
72+
This script runs on your machine. It creates a box with a browser, installs Browser Use, runs the agent once, and schedules it.
73+
74+
```python title="setup.py"
75+
import os
76+
77+
from upstash_box import Box
78+
79+
box = Box.create(
80+
runtime="python",
81+
browser=True,
82+
env={"ANTHROPIC_API_KEY": os.environ["ANTHROPIC_API_KEY"]},
83+
)
84+
print(box.id)
85+
86+
87+
def run(command):
88+
result = box.exec.command(command)
89+
if result.status != "completed":
90+
raise RuntimeError(result.result)
91+
92+
93+
# Install Browser Use and copy the agent in
94+
run("pip install browser-use")
95+
box.files.write(path="agent.py", content=open("agent.py").read())
96+
97+
# Run it once and print the report
98+
run("python3 agent.py")
99+
for file in box.files.list("reports"):
100+
print(box.files.read(f"reports/{file.name}"))
101+
102+
# Run it every day at 08:00 UTC
103+
box.schedule.exec(
104+
cron="0 8 * * *",
105+
command=["python3", "/workspace/home/agent.py"],
106+
)
107+
```
108+
109+
```bash
110+
python setup.py
111+
```
112+
113+
Example output after the box id. Stories and scores will vary:
114+
115+
```md
116+
## Top 3 AI Stories from Hacker News
117+
118+
1. **AI companies leak data to advertisers [pdf]** - 179 points
119+
- Link: https://jorgegarciaherrero.com/wp-content/interactivos/20260916-Prompt-like-a-butterfly-sting-like-a-tracker-(clean).pdf
120+
- Summary: The paper analyzes privacy practices of conversational AI services, finding that 6 out of 9 web services and 3 out of 8 Android apps leak conversation data to third parties. This includes sensitive information such as URLs, titles, prompts, and screenshots being shared alongside persistent user identifiers.
121+
122+
2. **Jeeves. Reasoning improves Jev-like decision models** - 54 points
123+
- Link: https://github.com/PostHog/jeeves
124+
125+
3. **Nvidia wants to put a watchdog chip next to every AI agent** - 197 points
126+
- Link: https://www.cnbc.com/2026/09/28/nvidia-releases.html
127+
```
128+
129+
The box pauses when idle. Each scheduled run wakes it, and the reports stay on the box.
130+
131+
<Note>
132+
Run `setup.py` once. Each run creates a new box with its own daily schedule.
133+
</Note>
134+
135+
---
136+
137+
## 4. Read the reports
138+
139+
Re-attach with the box id that `setup.py` printed:
140+
141+
```python title="reports.py"
142+
from upstash_box import Box
143+
144+
box = Box.get("your-box-id")
145+
146+
for file in box.files.list("reports"):
147+
print(box.files.read(f"reports/{file.name}"))
148+
```
149+
150+
```bash
151+
python reports.py
152+
```
153+
154+
Delete the box when you no longer need it:
155+
156+
```python
157+
box.delete()
158+
```
159+
160+
---
161+
162+
## Next steps
163+
164+
- [Schedules](/box/overall/schedules) to pause a schedule or get a webhook when a run finishes.
165+
- [Connect over CDP](/box/overall/browser/connect) to drive the box browser with Browser Use from your own machine.
166+
- [Browser](/box/overall/browser/overview) for the SDK's own `observe`, `act`, and `extract`.

‎box/overall/browser/connect.mdx‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Connect over CDP"
33
---
44

5-
The box browser is a real Chromium, and you can drive it with the tools you already use. `cdpUrl()` returns an authenticated Chrome DevTools Protocol WebSocket URL that Playwright, Puppeteer, or Stagehand can connect to directly. There is no browser to install and nothing to manage.
5+
The box browser is a real Chromium, and you can drive it with the tools you already use. `cdpUrl()` returns an authenticated Chrome DevTools Protocol WebSocket URL that Playwright, Puppeteer, Stagehand, or Browser Use can connect to directly. There is no browser to install and nothing to manage.
66

77
For a single no-LLM step without wiring up a CDP client, replaying an observed action with [`act(action)`](/box/overall/browser/ai-actions#replay-an-action-without-an-llm) is often enough. Reach for CDP when you want fully scripted, multi-step control.
88

@@ -76,6 +76,24 @@ await stagehand.init()
7676
await stagehand.act("click the first link")
7777
```
7878

79+
## Browser Use
80+
81+
[Browser Use](https://browser-use.com) can run its agent loop on the box browser:
82+
83+
```python agent.py
84+
import asyncio
85+
from browser_use import Agent, Browser, ChatAnthropic
86+
87+
agent = Agent(
88+
task="Open upstash.com/docs/box/overall/quickstart and return the install command",
89+
llm=ChatAnthropic(model="claude-sonnet-4-5"),
90+
browser=Browser(cdp_url=cdp_url),
91+
)
92+
93+
history = asyncio.run(agent.run())
94+
print(history.final_result())
95+
```
96+
7997
## Mixing CDP and SDK control
8098

8199
CDP clients and the SDK drive the same browser and the same tabs. A page opened by Playwright shows up in `box.browser.listTabs()`, and a tab created by the SDK is visible to Playwright. You can script the predictable steps like login and pagination with Playwright, hand the tab to [`act`](/box/overall/browser/ai-actions) for the steps that are easier to describe in natural language, and watch either through [Live View](/box/overall/browser/live-view).

‎box/overall/browser/overview.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ print(page.title)
7373
</Card>
7474

7575
<Card title="Connect over CDP" href="/box/overall/browser/connect">
76-
Drive the same browser with Playwright, Puppeteer, or Stagehand.
76+
Drive the same browser with Playwright, Puppeteer, Stagehand, or Browser Use.
7777
</Card>
7878
</CardGroup>
7979

‎docs.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,6 +2171,7 @@
21712171
"box/guides/code-review-agent",
21722172
"box/guides/langchain-deep-agents",
21732173
"box/guides/web-scraping-playwright",
2174+
"box/guides/browser-use",
21742175
"box/guides/ai-sdk-setup",
21752176
"box/guides/tanstack-setup",
21762177
"box/guides/eve-setup",

0 commit comments

Comments
 (0)