-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_10_boxes.py
More file actions
126 lines (100 loc) · 3.36 KB
/
Copy pathcreate_10_boxes.py
File metadata and controls
126 lines (100 loc) · 3.36 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""
Script to create 10 GBOX Linux boxes with 24-hour CDP URLs for parallel benchmarking.
Usage:
export GBOX_API_KEY="your-api-key"
python create_10_boxes.py
"""
import os
from gbox_sdk import GboxSDK
def create_gbox_boxes(num_boxes=10):
"""
Create multiple GBOX Linux boxes with 24-hour CDP URLs.
Args:
num_boxes: Number of boxes to create
Returns:
List of dicts with box_id, cdp_url, and box object
"""
# Get API key from environment
api_key = os.environ.get("GBOX_API_KEY")
if not api_key:
raise ValueError("GBOX_API_KEY environment variable must be set")
# Initialize GBOX SDK
gbox = GboxSDK(api_key=api_key)
boxes = []
print(f"🚀 Creating {num_boxes} GBOX Linux boxes with 24-hour CDP URLs...")
print()
for i in range(num_boxes):
print(f"Creating box {i+1}/{num_boxes}...", end=" ", flush=True)
# Create a new Linux box with 24-hour lifetime
box = gbox.create(
type="linux",
config={"expires_in": "24h"}
)
# Get CDP URL with 24-hour expiry (call client method directly)
cdp_url = box.client.v1.boxes.browser.cdp_url(box_id=box.data.id, expires_in="24h")
boxes.append({
"box_id": box.data.id,
"cdp_url": cdp_url,
"box": box # Keep reference for cleanup later
})
print(f"✓ Box ID: {box.data.id}")
print()
print(f"✅ Successfully created {num_boxes} boxes!")
print()
# Print summary
print("=" * 80)
print("SUMMARY")
print("=" * 80)
for i, box_info in enumerate(boxes):
print(f"Box {i}:")
print(f" ID: {box_info['box_id']}")
print(f" CDP: {box_info['cdp_url'][:80]}...")
print()
return boxes
def cleanup_boxes(boxes):
"""
Delete all GBOX boxes.
Args:
boxes: List of box info dicts with 'box' key
"""
print(f"🧹 Cleaning up {len(boxes)} boxes...")
for i, box_info in enumerate(boxes):
print(f"Deleting box {i+1}/{len(boxes)}... {box_info['box_id']}", end=" ", flush=True)
try:
box_info['box'].terminate()
print("✓")
except Exception as e:
print(f"✗ Error: {e}")
print("✅ Cleanup complete!")
if __name__ == "__main__":
# Create 10 boxes
boxes = create_gbox_boxes(num_boxes=10)
# Print usage instructions
print("=" * 80)
print("USAGE")
print("=" * 80)
print("To use these boxes with agisdk harness:")
print()
print("boxes = [")
for box_info in boxes:
print(f" {{'box_id': '{box_info['box_id']}', 'cdp_url': '{box_info['cdp_url']}'}},")
print("]")
print()
print("cdp_urls = [box['cdp_url'] for box in boxes]")
print("box_ids = [box['box_id'] for box in boxes]")
print()
print("harness = REAL.harness(")
print(" model='gpt-4o',")
print(" cdp_urls=cdp_urls,")
print(" box_ids=box_ids,")
print(" num_workers=10,")
print(" ...)")
print("=" * 80)
print()
# Ask user if they want to cleanup now
response = input("Do you want to delete these boxes now? (y/N): ")
if response.lower() == 'y':
cleanup_boxes(boxes)
else:
print("⚠️ Remember to delete boxes manually when done to avoid charges!")
print(" You can run cleanup later by calling cleanup_boxes(boxes)")