Skip to content

Commit e95f8b9

Browse files
alitariksahinclaude
andcommitted
DX-3107: Add the Scheduled Browser Use Agent guide for Box
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent b459f98 commit e95f8b9

2 files changed

Lines changed: 167 additions & 0 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`.

‎docs.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,7 @@
21692169
"box/guides/code-review-agent",
21702170
"box/guides/langchain-deep-agents",
21712171
"box/guides/web-scraping-playwright",
2172+
"box/guides/browser-use",
21722173
"box/guides/ai-sdk-setup",
21732174
"box/guides/tanstack-setup",
21742175
"box/guides/eve-setup",

0 commit comments

Comments
 (0)