def start(self, boot_timeout: float = 30.0) -> SmolVM: """Start the VM. Args: boot_timeout: Maximum seconds to wait for boot. Returns: self for method chaining. """
If a VM is already running, calling start() is a no-op and returns immediately.
The recommended way to manage VM lifecycle is using Python’s context manager:
Copy
Ask AI
from smolvm import SmolVMwith SmolVM() as vm: # VM automatically starts on context entry print(f"VM running: {vm.vm_id}") result = vm.run("hostname") print(result.output) # VM automatically stops and deletes on context exit
from smolvm import SmolVM# Create a VM without context managervm = SmolVM()vm.start()vm_id = vm.vm_idvm.close() # Release resources but don't delete# Later, reconnect to the same VMvm2 = SmolVM.from_id(vm_id)print(f"Reconnected to {vm2.vm_id}")print(f"Status: {vm2.status}") # VMState.RUNNING# Continue using the VMresult = vm2.run("uptime")print(result.output)
from smolvm import SmolVM# In a different Python session or scriptvm = SmolVM.from_id("persistent-agent-vm")print(f"Reconnected to {vm.vm_id}")print(f"Status: {vm.status}")result = vm.run("uptime")print(result.output)
3
Clean up when done
Copy
Ask AI
vm = SmolVM.from_id("persistent-agent-vm")vm.stop()vm.delete()print("VM permanently deleted")
vm = SmolVM()vm.start()# Wait up to 60 seconds for SSHvm.wait_for_ssh(timeout=60.0)print("SSH is ready")# Now run commandsresult = vm.run("whoami")print(result.output)
You typically don’t need to call wait_for_ssh() explicitly. The run() method automatically waits for SSH on first use.