> ## Documentation Index
> Fetch the complete documentation index at: https://hyperbrowser.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Authenticate REST, SDK, and CLI requests with the `x-api-key` header using the `HYPERBROWSER_API_KEY` environment variable (create keys at https://app.hyperbrowser.ai).
> Always stop browser sessions (`sessions.stop(id)` / `PUT /api/session/{id}/stop`) and sandboxes (`sandboxes.stop(id)` / `PUT /api/sandbox/{id}/stop`) in `try`/`finally` blocks to avoid idle billing.
> Choose the right surface: use Web API (`/api/web/fetch`, `batch-fetch`, `crawl`, `search`) for stateless reading and extraction (prefer it over legacy `/api/scrape`); Browser Sessions (`/api/session`) for interactive, authenticated, or Playwright/Puppeteer workflows; Cloud Agents (`/api/task/*`) for autonomous browser tasks; and Sandboxes (`/api/sandbox`) for isolated Linux or macOS code execution.
> Use `@hyperbrowser/sdk` for Node.js/TypeScript, `hyperbrowser` 1.0+ typed-dict request params for Python (avoid legacy Pydantic request classes), the unified `hx` CLI for terminal workflows, and hosted OAuth MCP at `https://mcp.hyperbrowser.ai/mcp/web` (web tools; use `https://mcp.hyperbrowser.ai/mcp` only when browser, sandbox, admin, and usage tools are needed).

# Human-in-the-Loop Cloud Agents with Credential Fill

> Attach an encrypted vault to a session, inject credentials safely, hand off a Live View URL to an operator if needed, and run Browser Use

This recipe combines three primitives so an autonomous browser agent can operate inside an authenticated account without ever seeing plaintext passwords:

1. **Pre-created browser session** attached to an encrypted [Vault](https://hyperbrowser.ai/docs/sandboxes/vaults.md) and short-lived [Live View](https://hyperbrowser.ai/docs/sessions/live-view.md) token (`liveViewTtlSeconds`).
2. **[Credential Fill](https://hyperbrowser.ai/docs/sessions/credentials.md)** so secrets are decrypted only on the browser host and typed into allowed origins.
3. **[Browser Use](https://hyperbrowser.ai/docs/agents/browser-use.md)** running against `sessionId` with `keepBrowserOpen: true` so a human can inspect or intervene via `session.liveUrl`.

**Required API key scopes:** `browser.sessions.create`, `browser.sessions.update`, `browser.sessions.stop`, `secrets.use`, `agents.browser-use.run`, `agents.browser-use.read`.

## Prerequisites

* `HYPERBROWSER_API_KEY` exported in your shell and a pre-created vault named `portal-login` containing `USERNAME` and `PASSWORD` entries with `allowedOrigins` configured for `https://portal.example.com`.
* `@hyperbrowser/sdk` (TypeScript) or `hyperbrowser` (Python) installed.

***

## End-to-End Flow

```typescript TypeScript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { Hyperbrowser } from "@hyperbrowser/sdk";

const client = new Hyperbrowser({ apiKey: process.env.HYPERBROWSER_API_KEY });

async function runAuthenticatedAgent() {
  // 1. Create a session bound to a pre-created vault (USERNAME + PASSWORD)
  const session = await client.sessions.create({
    useStealth: true,
    solveCaptchas: true,
    liveViewTtlSeconds: 1800, // 30-minute Live View token
    credentials: [{ vault: "portal-login" }],
  });

  console.log("Human-in-the-loop Live View URL:", session.liveUrl);

  try {
    // 2. Navigate to the login page and fill credentials without exposing values
    await client.agents.browserUse.startAndWait({
      sessionId: session.id,
      keepBrowserOpen: true,
      task: "Navigate to https://portal.example.com/login and stop once the login form is visible.",
      maxSteps: 5,
    });

    const fillResult = await client.sessions.credentials.fill(session.id, {
      vault: "portal-login",
      fields: [
        { field: "USERNAME", selector: 'input[name="email"]' },
        { field: "PASSWORD", selector: 'input[name="password"]' },
      ],
    });
    console.log("Credential fill outcomes:", fillResult.fields);

    // 3. Complete the authenticated workflow with Browser Use
    const task = await client.agents.browserUse.startAndWait({
      sessionId: session.id,
      keepBrowserOpen: false,
      task: "Click Sign In, open Billing -> Invoices, and return the latest invoice number and amount.",
      maxSteps: 15,
    });

    console.log("Agent result:", task.data?.finalResult);
  } finally {
    await client.sessions.stop(session.id);
  }
}

runAuthenticatedAgent().catch(console.error);
```

```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import os
from hyperbrowser import Hyperbrowser

client = Hyperbrowser(api_key=os.environ["HYPERBROWSER_API_KEY"])


def run_authenticated_agent():
    session = client.sessions.create({
        "use_stealth": True,
        "solve_captchas": True,
        "live_view_ttl_seconds": 1800,
        "credentials": [{"vault": "portal-login"}],
    })

    print("Human-in-the-loop Live View URL:", session.live_url)

    try:
        client.agents.browser_use.start_and_wait({
            "session_id": session.id,
            "keep_browser_open": True,
            "task": "Navigate to https://portal.example.com/login and stop once the login form is visible.",
            "max_steps": 5,
        })

        fill_result = client.sessions.credentials.fill(session.id, {
            "vault": "portal-login",
            "fields": [
                {"field": "USERNAME", "selector": 'input[name="email"]'},
                {"field": "PASSWORD", "selector": 'input[name="password"]'},
            ],
        })
        print("Credential fill outcomes:", fill_result.fields)

        task = client.agents.browser_use.start_and_wait({
            "session_id": session.id,
            "keep_browser_open": False,
            "task": "Click Sign In, open Billing -> Invoices, and return the latest invoice number and amount.",
            "max_steps": 15,
        })
        print("Agent result:", task.data.final_result)
    finally:
        client.sessions.stop(session.id)


if __name__ == "__main__":
    run_authenticated_agent()
```

> [!TIP]
>
> Need a read-only observer link for dashboards or audit viewers? Pass `viewOnlyLiveView: true` when creating the session.

## Expected output

* Logs the 30-minute `Human-in-the-loop Live View URL` for operator takeover or audit inspection.
* Prints per-field credential fill statuses (`filled`) without returning plaintext secret values, followed by the extracted invoice number and amount from `task.data.finalResult`.

## Next Steps

* [Credential Fill](https://hyperbrowser.ai/docs/sessions/credentials.md) — TOTP one-time codes, 1Password references, and origin allowlists.
* [Live View](https://hyperbrowser.ai/docs/sessions/live-view.md) — short-lived tokens and read-only observer links.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.