2025-05-29 14:20:03 +02:00
|
|
|
import asyncio
|
|
|
|
|
|
2026-02-04 14:16:07 +01:00
|
|
|
from daytona import AsyncDaytona
|
2025-05-29 14:20:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
|
async with AsyncDaytona() as daytona:
|
|
|
|
|
print("Creating sandbox")
|
|
|
|
|
sandbox = await daytona.create()
|
|
|
|
|
print("Sandbox created")
|
|
|
|
|
|
2026-01-20 15:43:03 +01:00
|
|
|
_ = await sandbox.set_labels(
|
2025-05-29 14:20:03 +02:00
|
|
|
{
|
2026-01-20 15:43:03 +01:00
|
|
|
"public": "true",
|
2025-05-29 14:20:03 +02:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
print("Stopping sandbox")
|
|
|
|
|
await daytona.stop(sandbox)
|
|
|
|
|
print("Sandbox stopped")
|
|
|
|
|
|
|
|
|
|
print("Starting sandbox")
|
|
|
|
|
await daytona.start(sandbox)
|
|
|
|
|
print("Sandbox started")
|
|
|
|
|
|
|
|
|
|
print("Getting existing sandbox")
|
2025-06-17 09:07:11 +02:00
|
|
|
existing_sandbox = await daytona.get(sandbox.id)
|
2025-05-29 14:20:03 +02:00
|
|
|
print("Get existing sandbox")
|
|
|
|
|
|
|
|
|
|
response = await existing_sandbox.process.exec('echo "Hello World from exec!"', cwd="/home/daytona", timeout=10)
|
|
|
|
|
if response.exit_code != 0:
|
|
|
|
|
print(f"Error: {response.exit_code} {response.result}")
|
|
|
|
|
else:
|
|
|
|
|
print(response.result)
|
|
|
|
|
|
2025-10-03 10:36:48 +02:00
|
|
|
result = await daytona.list()
|
|
|
|
|
print("Total sandboxes count:", result.total)
|
2025-06-12 13:45:20 +00:00
|
|
|
|
2025-10-03 10:36:48 +02:00
|
|
|
print(f"Printing first sandbox -> id: {result.items[0].id} state: {result.items[0].state}")
|
2025-05-29 14:20:03 +02:00
|
|
|
|
|
|
|
|
print("Removing sandbox")
|
|
|
|
|
await daytona.delete(sandbox)
|
|
|
|
|
print("Sandbox removed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
asyncio.run(main())
|