Persistent sessions let you save session state when a session ends, then restore that state in future sessions. Both browser and desktop sessions support persistence:
Browser sessions save cookies and storage state — useful for staying logged into websites across runs
Desktop sessions save a full VM snapshot — preserving installed software, files, and system configuration
This is useful for:
Staying logged into websites or desktop apps across automation runs
Preserving user preferences, installed software, and settings
Terminate the session - state is automatically saved
Create a new session with environment_id set to the original session ID
The new session starts with all saved state restored
The environment_id is the id returned by POST /computers when you created the original persistent session (e.g., comp_abc123). This is the same ID shown in the dashboard environments list.
First, create a session with persistent: true and perform your login:
Copy
Ask AI
from tzafon import Computerclient = Computer()# Create a persistent sessionwith client.create(kind="browser", persistent=True) as computer: # Navigate to login page computer.navigate("https://example.com/login") computer.wait(2) # Click email field and type computer.click(600, 230) computer.type("user@example.com") # Click password field and type computer.click(600, 300) computer.type("your_password") # Click sign in button computer.click(600, 380) computer.wait(5) # Verify logged in result = computer.screenshot() print(f"Logged in: {computer.get_screenshot_url(result)}") # Save the session ID for later print(f"Session ID (save this): {computer.id}")# Session ends - state is saved automatically
Later, create a new session using the saved environment_id:
Copy
Ask AI
from tzafon import Computerclient = Computer()# Restore from previous persistent sessionsaved_session_id = "comp_1275553034519934828" # From Step 1with client.create( kind="browser", environment_id=saved_session_id) as computer: # Navigate to the site - you should already be logged in! computer.navigate("https://example.com") computer.wait(3) # Take a screenshot to verify logged-in state result = computer.screenshot() print(f"Still logged in: {computer.get_screenshot_url(result)}") # Continue with your automation...
Desktop sessions work the same way — use persistent: true to save a VM snapshot, then environment_id to restore it. The full VM state is preserved, including installed packages, files, and running services.
Copy
Ask AI
from tzafon import Computerclient = Computer()# Create a persistent desktop session and set it upwith client.create(kind="desktop", persistent=True) as computer: # Install software, configure the environment computer.execute("sudo apt-get install -y nodejs") computer.execute("mkdir -p ~/project && cd ~/project && npm init -y") computer.wait(3) result = computer.screenshot() print(f"Setup complete: {computer.get_screenshot_url(result)}") print(f"Session ID (save this): {computer.id}")# Session ends - full VM snapshot is saved
Restore the desktop environment later — all installed software and files will be intact:
Copy
Ask AI
saved_session_id = "comp_1275553034519934828" # From abovewith client.create( kind="desktop", environment_id=saved_session_id) as computer: # nodejs is already installed, project directory exists computer.execute("cd ~/project && node --version") computer.wait(2) result = computer.screenshot() print(f"Restored: {computer.get_screenshot_url(result)}")
Restoring does not automatically keep saving. If you pass environment_id without persistent: true, the session starts from the saved state but will not save changes when it ends. Set persistent: true on restored sessions if you want updates to be saved.
Sessions expire. Saved state has a retention period. If you haven’t used an environment in a long time, you may need to log in again.
Store your session IDs. Save the session id from persistent sessions to a database or config file so you can restore them later.
Persistent sessions are designed with security in mind:
No credentials stored. We never store your login credentials (usernames, passwords). For browser sessions, only session cookies are preserved. For desktop sessions, a VM snapshot is saved.
Encrypted at rest. Saved state is encrypted before storage.
You control retention. Saved state remains available as long as you need it.
Encryption happens when the session terminates and state is persisted.