The SDK is fully typed end‑to‑end with Pydantic models. Import types from hyperbrowser.models and pass method parameters as model instances.
from hyperbrowser.models import CreateSessionParams
Parameter models: Most methods accept a single Pydantic “params” object (parameter object/DTO). Create an instance and pass only the fields you need — None/unset fields are omitted on the wire.
Field names and aliases: Use Pythonic field names in code; the SDK serializes to API field names automatically via serialization_alias (e.g., use_ultra_stealth → useUltraStealth).
Sandbox APIs work in two layers.Sandbox control methods use your API key to create, inspect, connect to, and stop sandboxes. When you create or connect to a sandbox, the SDK also retrieves a sandbox-scoped runtime token and returns an authenticated SandboxHandle.Sandbox VM operations run inside that started sandbox and use the runtime token on the handle automatically. The SDK handles runtime token refreshes for you, so once you have a running SandboxHandle, you can call files, processes, terminal, networking, and snapshot methods without managing runtime auth yourself.
from hyperbrowser.models import SandboxListParamsresponse = client.sandboxes.list( SandboxListParams( status="active", # optional: sandbox status filter search="sdk", # optional: search term page=1, # optional: page number limit=20, # optional: results per page ))print(response.total_count)print([entry.id for entry in response.sandboxes])
from hyperbrowser.models import SandboxSnapshotListParamssnapshots = client.sandboxes.list_snapshots( SandboxSnapshotListParams( image_name="node", # optional: only snapshots for this image status="created", # optional: snapshot status filter limit=10, # optional: max results ))print([snapshot.snapshot_name for snapshot in snapshots.snapshots])
from hyperbrowser.models import CreateSandboxParamssandbox = client.sandboxes.create( CreateSandboxParams( snapshot_name="node-after-setup", # required: snapshot name snapshot_id="snapshot-id", # optional: pin a specific snapshot version ))
Use connect(...) to re-authenticate a running sandbox, refresh its runtime token, and return a SandboxHandle for runtime operations. If you already have a handle, call sandbox.connect() to re-authenticate it in place.
sandbox = client.sandboxes.connect( "sandbox-id", # running sandbox ID)sandbox.connect() # re-authenticate an existing handle in place
Use sandbox.processes.start(...) for long-running processes.
process = sandbox.processes.start( "sleep 30", cwd="/tmp", # optional: working directory env={"FOO": "bar"}, # optional: environment variables run_as="root", # optional: run as a specific sandbox user)print(process.id)
process.write_stdin( data="hello\n", # optional: stdin payload encoding="utf8", # optional: "utf8" or "base64" eof=True, # optional: close stdin after this write)
upload = sandbox.files.upload_url( "/tmp/upload.txt", # target path inside the sandbox one_time=True, # optional: invalidate the URL after one use expires_in_seconds=60, # optional: URL lifetime)print(upload.method, upload.url)
download = sandbox.files.download_url( "/tmp/hello.txt", # source path inside the sandbox one_time=True, # optional: invalidate the URL after one use expires_in_seconds=60, # optional: URL lifetime)print(download.method, download.url)
terminal = sandbox.terminal.get( "terminal-id", # terminal ID include_output=True, # optional: include buffered output)print(len(terminal.current.output or []))
Programmatically control the browser with low-level actions.
For the session-id parameter, you can also just pass in the detailed session object itself, and it is actually recommended to do so.