Skip to content

Commit 9f0f9b5

Browse files
committed
Harden URL checks in the OpenAI CUA templates.
Make clipboard-based blocklist lookups best-effort so browser runs don't fail on empty reads, and translate forward actions in pending batches to keep navigation support consistent. Made-with: Cursor
1 parent 16536a0 commit 9f0f9b5

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

pkg/templates/python/openai-computer-use/agent/agent.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,14 @@ def handle_item(self, item):
340340
}
341341

342342
if self.computer.get_environment() == "browser":
343-
current_url = self.computer.get_current_url()
344-
check_blocklisted_url(current_url)
343+
try:
344+
current_url = self.computer.get_current_url()
345+
check_blocklisted_url(current_url)
346+
except Exception as exc:
347+
self._emit_event(
348+
"backend",
349+
{"op": "get_current_url.skipped", "detail": str(exc)},
350+
)
345351

346352
return [call_output]
347353
return []

pkg/templates/python/openai-computer-use/computers/kernel_computer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ def _build_pending_batch(actions: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
312312
if action_type == "back":
313313
pending.extend(_back_batch_actions())
314314
continue
315+
if action_type == "forward":
316+
pending.extend(_forward_batch_actions())
317+
continue
315318
if action_type in ("url", "screenshot"):
316319
continue
317320
raise ValueError(f"Unknown CUA action type: {action_type}")

pkg/templates/typescript/openai-computer-use/lib/agent.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,17 @@ export class Agent {
202202
if (!this.ackCb(msg)) throw new Error(`Safety check failed: ${msg}`);
203203
}
204204

205-
const currentUrl = await this.computer.getCurrentUrl();
206-
utils.checkBlocklistedUrl(currentUrl);
205+
if (this.computer.getEnvironment() === 'browser') {
206+
try {
207+
const currentUrl = await this.computer.getCurrentUrl();
208+
utils.checkBlocklistedUrl(currentUrl);
209+
} catch (error) {
210+
this.emit('backend', {
211+
op: 'get_current_url.skipped',
212+
detail: error instanceof Error ? error.message : String(error),
213+
});
214+
}
215+
}
207216

208217
const screenshotOutput = {
209218
type: 'computer_screenshot',

pkg/templates/typescript/openai-computer-use/lib/kernel-computer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ function buildPendingBatch(actions: CuaAction[]): BatchAction[] {
345345
pending.push(...backBatchActions());
346346
continue;
347347
}
348+
if (actionType === 'forward') {
349+
pending.push(...forwardBatchActions());
350+
continue;
351+
}
348352
if (actionType === 'url' || actionType === 'screenshot') {
349353
continue;
350354
}

0 commit comments

Comments
 (0)