-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen_box.py
More file actions
83 lines (71 loc) · 2.41 KB
/
Copy pathopen_box.py
File metadata and controls
83 lines (71 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
"""
Standalone script to create a GBOX box with proper resolution and browser setup.
This tests the correct order of operations:
1. Create box
2. Set resolution
3. Open browser
"""
from gbox_sdk import GboxSDK
import time
# Configuration - Box Resolution (desktop display)
BOX_WIDTH = 1280
BOX_HEIGHT = 980
print("=" * 60)
print("GBOX Box Creation Script")
print("=" * 60)
# Step 1: Create a fresh GBOX box
print("\n[1/3] Creating GBOX box...")
gbox = GboxSDK()
box = gbox.create(type="linux", config={"expires_in": "2h"})
box_id = box.data.id
print(f"✅ Box created: {box_id}")
print(f" VNC URL: https://app.gbox.ai/box/{box_id}")
# Step 2: Set the resolution BEFORE opening browser
print(f"\n[2/3] Setting box resolution to {BOX_WIDTH}x{BOX_HEIGHT}...")
try:
box.resolution.set(width=BOX_WIDTH, height=BOX_HEIGHT)
print(f"✅ Resolution set successfully")
# Give the display server a moment to adjust
print(" Waiting 2 seconds for display server to stabilize...")
time.sleep(2)
except Exception as e:
print(f"⚠️ Warning: Failed to set resolution: {e}")
print(" Continuing anyway...")
# Step 3: Open browser and get CDP URL
print("\n[3/3] Opening browser in the box...")
try:
open_result = box.client.v1.boxes.browser.open(
box_id=box_id,
show_controls=False
)
cdp_url = open_result.cdp_url
print(f"✅ Browser opened successfully")
print(f" CDP URL: {cdp_url}")
except Exception as e:
print(f"❌ Failed to open browser: {e}")
print("\nCleaning up...")
try:
box.terminate()
print("Box terminated")
except:
pass
exit(1)
# Success!
print("\n" + "=" * 60)
print("✅ SUCCESS - Box is ready!")
print("=" * 60)
print(f"\nBox ID: {box_id}")
print(f"VNC URL: https://app.gbox.ai/box/{box_id}")
print(f"CDP URL: {cdp_url}")
print(f"Box Resolution (desktop): {BOX_WIDTH}x{BOX_HEIGHT}")
print("\nNote: The browser viewport will be set by Playwright when you run tasks")
print(" (typically 1280x720 for REAL Bench)")
print("\nYou can now:")
print(" 1. Open the VNC URL in your browser to see the box")
print(" 2. Use the CDP URL to connect Playwright")
print(" 3. Use this box_id in persistent_box_starter.py")
print("\nThe box will expire in 2 hours.")
print("\nTo terminate the box manually, run:")
print(f" python -c \"from gbox_sdk import GboxSDK; GboxSDK().get('{box_id}').terminate()\"")
print("=" * 60)