Overview
BrowserSession gives you a real Chromium browser running inside a SmolVM sandbox. You can automate it with Playwright, take screenshots, transfer files, or watch the session live through noVNC — all without installing a browser on your host.
Use browser sessions when your agent or script needs to interact with websites, fill out forms, capture screenshots, or perform computer-use tasks.
Import
Constructor
Configuration for a new browser session. Mutually exclusive with
session_id. If omitted (and session_id is omitted), SmolVM creates a session with sensible defaults.ID of an existing session to reconnect to. Mutually exclusive with
config.Raises
ValueError: If bothconfigandsession_idare provided.
Class methods
from_id
Reconnect to an existing browser session by its ID.The session identifier returned when the session was first created.
A BrowserSession instance connected to the existing session.
Lifecycle methods
start
Boot the sandbox, launch the browser, and expose the Chrome DevTools Protocol (CDP) endpoint on localhost.Returns
self for method chaining.start() completes you can access the CDP URL from the session’s info property and connect Playwright or any other CDP client.
stop
Stop the browser and shut down the underlying sandbox. The session can be restarted later.Returns
self for method chaining.delete
Permanently remove the session and its sandbox.Browser automation
connect_playwright
Connect a PlaywrightBrowser instance to the running browser session over CDP.
A Playwright
Browser object you can use to create pages, navigate, click, and extract content.You need
playwright installed locally. Install it with pip install playwright.screenshot
Capture a screenshot of the current browser viewport and save it to a local file.Local file path where the screenshot will be saved (PNG format).
The path to the saved screenshot.
open_live_view
Open the noVNC live-view URL in your default web browser. This lets you watch the browser session in real time.File transfer
push_file
Copy a local file into the browser session’s sandbox.Path to the file on your host machine.
Destination path inside the sandbox.
pull_file
Copy a file from the sandbox to your host machine.Path to the file inside the sandbox.
Destination path on your host machine.
Diagnostics
collect_artifacts
Package guest logs, downloads, and recordings into a tar archive.Path to the tar archive on your host.
logs
Retrieve combined host and guest logs for the session.Return only the last N lines. If omitted, returns all available logs.
Combined log output.
Context manager
BrowserSession supports thewith statement for automatic lifecycle management:
__enter__): starts the session if it was newly created.
On exit (__exit__): stops and deletes the session, releasing all resources.
Usage examples
Basic browser session
Take a screenshot
Custom browser configuration
Reconnect to an existing session
Related
- BrowserSessionConfig - Configure browser session options
- SmolVM - General sandbox management
- AI agent integration - Use browser sessions with agent frameworks