from time import sleep
from e2b_code_interpreter import Sandbox
sbx = Sandbox.create()
print('Sandbox created', sbx.sandbox_id)
# Wait for a few seconds to collect some metrics
sleep(10)
metrics = sbx.get_metrics()
# You can also get the metrics by sandbox ID:
# metrics = Sandbox.get_metrics(sbx.sandbox_id)
print('Sandbox metrics', metrics)
# Sandbox metrics
# [
# SandboxMetric(
# cpu_count=2,
# cpu_used_pct=13.97,
# disk_total=2573185024, # in bytes
# disk_used=1514856448, # in bytes
# mem_total=507592704, # in bytes
# mem_used=30588928, # in bytes
# timestamp=datetime.datetime(2025, 7, 28, 8, 8, 15, tzinfo=tzutc()),
# ),
# SandboxMetric(
# cpu_count=2,
# cpu_used_pct=0.1,
# disk_total=2573185024, # in bytes
# disk_used=1514856448, # in bytes
# mem_total=507592704, # in bytes
# mem_used=31084544, # in bytes
# timestamp=datetime.datetime(2025, 7, 28, 8, 8, 20, tzinfo=tzutc()),
# ),
# ]