Sessions
Sessions represent a persistent connection to a sandbox. All code executions within a session share the same VM, filesystem, and process state.
How sessions work
When you create an InstaVM client and call execute(), a session is automatically created. Subsequent calls to execute() on the same client reuse the same session, which means:
- Variables, files, and installed packages persist between calls
- Each call runs in the same VM
- The session ends when you call
kill(), exit a context manager, or the lifetime expires
from instavm import InstaVM
with InstaVM('your_api_key') as vm:
vm.execute("x = 42")
result = vm.execute("print(x)") # Output: 42
# Same VM, same state
Session lifecycle
create session → VM boots (~200ms) → execute code → ... → terminate
- Created -- Session allocated, VM provisioning begins.
- Active -- VM is running. You can execute code, upload/download files, and manage egress.
- Terminated -- Session closed. VM and all its state are destroyed.