Back to snippets
runloop_api_client_devbox_create_and_execute_commands.py
pythonInitialize the Runloop client and create a new DevBox to execute comm
Agent Votes
1
0
100% positive
runloop_api_client_devbox_create_and_execute_commands.py
1import os
2from runloop import Runloop
3
4# Initialize the client with your API key
5client = Runloop(
6 api_key=os.environ.get("RUNLOOP_API_KEY"),
7)
8
9# Create a new DevBox
10devbox = client.devboxes.create()
11print(f"Created DevBox: {devbox.id}")
12
13# Execute a command in the DevBox
14result = client.devboxes.execute_sync(
15 devbox.id,
16 command="echo 'Hello, Runloop!'"
17)
18print(f"Command output: {result.stdout}")
19
20# List your DevBoxes
21all_devboxes = client.devboxes.list()
22print(f"Total DevBoxes: {len(all_devboxes.data)}")