Skip to main content
STOP. Do not read past this section until you have read and followed /quickstart.md.Goal: produce a reliable SDK automation script. The intended authoring flow is generate then edit, not write browser automation from scratch.Do not hand-write SDK code with element IDs, selectors, or form fields from memory. Element IDs, selectors, and field mappings must come from a live observe() call, CLI notte page observe output, or generated workflow code. Guessed browser targets fail on real pages.Use the Notte skill and CLI to inspect the live site, validate actions/selectors, handle auth/session state, and export workflow code with notte sessions workflow-code before using SDK docs or SDK code.SDK reference pages are for understanding, running, or editing generated workflow code. They are not the starting point for manually authoring the initial browser automation. SDK-first code is guesswork on real-world pages with dynamic selectors, auth state, CAPTCHAs, and anti-bot behavior.
Every Notte session follows a predictable lifecycle from creation to termination. Understanding this lifecycle helps you build reliable automation workflows and manage resources effectively.

Session States

Sessions transition through these states:
  • active - Session is running and ready to accept operations
  • closed - Session has been terminated normally
  • error - Session encountered an error and terminated unexpectedly
  • timed_out - Session exceeded its timeout duration

Creating a Session

Create a new session using the context manager pattern (recommended):
Always use the context manager (with statement) to ensure sessions are properly stopped, even if errors occur.

Getting Session Details

Retrieve current information about your session:
session_id
string
Unique identifier for the session
status
string
Current status: active, closed, error, or timed_out
created_at
datetime
Session creation timestamp
closed_at
datetime | None
Session closure timestamp (None if still active)
last_accessed_at
datetime
Last operation timestamp
timeout_minutes
integer
Session timeout in minutes
duration
timedelta
Total session duration

Listing Sessions

Query all your active sessions:

Stopping a Session

Sessions are automatically stopped when using the context manager, but you can also stop them manually:
Stopping a session is idempotent - you can safely call it multiple times without errors.

Complete Lifecycle Example

Here’s a complete example demonstrating best practices for session management:

Connecting to Existing Sessions

You can reconnect to an existing session using its session_id:

Error Handling

The context manager automatically handles cleanup, even when errors occur:

Best Practices

Follow these patterns to build reliable, cost-effective automation:

1. Always Use Context Managers

The with statement guarantees cleanup:
context_manager.py

2. Set Appropriate Timeouts

Match timeout to task duration with a buffer for delays:
  • Quick tasks: 3-5 minutes (default is 3)
  • Data scraping: 10-15 minutes
  • Long workflows: 20-30 minutes
timeout_example.py

3. Monitor Session State

Check session status before long-running operations:
monitor_state.py

4. Handle Cleanup Gracefully

Even with context managers, handle interrupts:
handle_interrupts.py

Session Lifecycle Diagram

Next Steps

Session Configuration

Configure sessions with advanced options

Recordings

Record and replay session activity

Live View

Watch sessions in real-time

Cookies

Persist authentication across sessions