Docs
Dashboard
API reference / BrowserBeta

Run a Playwright script

Runs JavaScript with Node inside the session's own sandbox, next to its Chrome (the session needs a browser, else 409 browser_disabled, and a shell, else 409 shell_disabled). In scope: page, context, browser (Playwright, already connected), env and console; top-level await works; do not call browser.close(). The reply streams NDJSON exactly like a streaming exec. Never replayed by Idempotency-Key.

POST/v1/sessions/{id}/browser/script

Request

Method and pathPOST/v1/sessions/{id}/browser/script
Base URLhttps://api.boxline.dev
AuthenticationYour API key in the x-api-key header (or Authorization: Bearer). The examples read it from BOXLINE_API_KEY.

Path parameters

NameTypeDefaultAllowed valuesDescription
idrequiredstring––

Body

JSON with content-type: application/json. Required.

NameTypeDefaultAllowed valuesDescription
coderequiredstring––Up to 200000 characters.
envobject––
timeoutMsinteger120000–From 1000 to 600000.
credentialsstring[]––Credentials the script's step() calls may use as placeholders (scope "agent" or "all"). The values never go into the machine: step() runs on the platform, which fills them in. Hidden in the output. The grant is for this run only and ends when the script exits or the caller disconnects. A credential the session's profile links is offered only when listed here. Up to 50 items.
allowWithExtensionsbooleanfalse–Allow credentials in a session with Chrome extensions, which can read every typed value (400 variables_with_extensions otherwise). Signed into the script's grant; logs a warning in the session's events.
aiobject––The model step() and extract() use unless a call, or useModel(), picks its own. With only model, the provider is the one that lists it; with only provider, its fast step model. Needs the plan's steps.
ai.providerstring–anthropic, openai, xai, googleAnthropic Claude, OpenAI, Grok (xAI), Google Gemini. Grok and Gemini have no computer use (mode computer is 400).
ai.modelstring––
curl -X POST "https://api.boxline.dev/v1/sessions/$SESSION_ID/browser/script" \  -H "x-api-key: $BOXLINE_API_KEY" \  -H "content-type: application/json" \  -d '{    "code": "await page.goto('\''https://example.com'\''); console.log(await page.title());"  }'

Responses

200 OK

The script's output as it happens.

  • application/x-ndjson: Newline-delimited JSON (one object per line), sent as it happens.

Fields

NameTypeDefaultAllowed valuesDescription
typestring–stdout, stderr, exit
datastring––
exitCodeinteger | null––
timedOutboolean––
durationMsinteger––
truncatedboolean––
Response 200
{"type":"stdout","data":"Example Domain\n"}{"type":"exit","exitCode":0,"timedOut":false,"durationMs":812}

Errors

Errors have a matching HTTP status and the same body. code is stable, so check it in your code; message is for people. See Errors and request ids.

StatusCodesWhen
400 Bad Requestinvalid_request, invalid_json, invalid_cursor, invalid_idempotency_key, invalid_extension, variables_with_extensions, terms_not_accepted, invalid_reset_token, invalid_confirmation_code, wrong_password, no_password, invalid_next, invalid_oauth_tokenThe request is not valid.
401 UnauthorizedunauthorizedMissing or invalid API key.
404 Not Foundnot_found, invite_not_found, provider_unavailableNo such thing in this project (or organization), or no such route.
409 Conflictsession_not_running, shell_disabled, browser_disabled, nothing_saved, not_resumable, invalid_state, conflict, email_taken, identity_in_use, provider_already_linked, last_sign_in_method, not_impersonating, machine_too_old, too_many_credential_values, limit_reached, terms_version_mismatch, no_project, last_owner, organization_not_empty, project_has_sessions, already_member, invite_pending, idempotency_in_progressThe current state does not allow it, or a request with this Idempotency-Key is still being answered.
502 Bad Gatewaymachine_error, machine_unreachable, page_unreachableThe session machine failed or could not be reached, or, for fetch, screenshot, pdf and extract, the page could not be loaded.
Error body
{  "error": {    "code": "not_found",    "message": "session not found",    "requestId": "req_4fJx0aQm2Lk9Pz7N"  }}

Use with the browser

A script can use the browser and the shell together: Playwright and step() for the pages, child_process and fs for the workspace. See Browser, shell and files together.

# The body is JSON: put the script (total.js, above) in "code".jq -n --rawfile code total.js '{code: $code, timeoutMs: 300000}' |  curl -N -X POST https://api.boxline.dev/v1/sessions/$SESSION_ID/browser/script \    -H "x-api-key: $BOXLINE_API_KEY" \    -H "content-type: application/json" \    -d @-

Learn more

These docs describe a beta API. Endpoints, fields and SDK methods may change before general availability; breaking changes will be listed in the changelog.