> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://platform.bctrl.ai/llms.txt.
> For full documentation content, see https://platform.bctrl.ai/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://platform.bctrl.ai/_mcp/server.

# Hosted agents

> Run Stagehand and browser-use agents inside a runtime with a single call.

Hosted agents are [invocations](/sdk/invocations) that BCTRL runs inside a runtime. Describe the task in natural language and BCTRL drives the browser for you. No CDP connection required. The work ranges from a single Stagehand action to a structured extraction to a multi-step browser-use agent.

## Stagehand

Stagehand exposes four hosted actions through a typed helper.

```ts
import { z } from "zod";

// One natural-language action
await bctrl.runtimes.invocations.stagehand.act(runtime.id, {
  instruction: "Click the export button.",
});

// Inspect the page
await bctrl.runtimes.invocations.stagehand.observe(runtime.id, {
  instruction: "What filters are available?",
});

// Structured extraction
const result = await bctrl.runtimes.invocations.stagehand.extract(runtime.id, {
  instruction: "Extract the invoice total.",
  schema: z.object({ total: z.number() }),
});

// Multi-step agent flow
await bctrl.runtimes.invocations.stagehand.agent(runtime.id, {
  instruction: "Download every invoice from the last quarter.",
  maxSteps: 30,
});
```

## browser-use

```ts
await bctrl.runtimes.invocations.browserUse.agent(runtime.id, {
  instruction: "Find the cheapest flight to Lisbon and add it to the cart.",
  maxSteps: 50,
  useVision: "auto",
});
```

browser-use exposes deeper controls when you need them: `enablePlanning`, `maxFailures`, `stepTimeoutMs`, `sensitiveData`, and more.

## Wait for the result

The helpers return an invocation immediately. To run and block on the answer, use `createAndWait`:

```ts
const invocation = await bctrl.runtimes.invocations.createAndWait(
  runtime.id,
  { action: "browserUse", instruction: "Reconcile this month's transactions." },
  { timeoutMs: 120_000 }
);

console.log(invocation.status, invocation.output);
```

## Choosing a model

Point an agent at a saved [AI provider](/sdk/ai-providers) and tune the call.

```ts
await bctrl.runtimes.invocations.stagehand.agent(runtime.id, {
  instruction: "Summarize the dashboard.",
  aiProviderId: "aip_123",
  model: "claude-opus-4-8",
  temperature: 0.2,
});
```

Agents can also be given [tools and toolsets](/sdk/tools) with `toolsetId` and `toolIds`.

## Next

* [Invocations](/sdk/invocations) - the underlying model
* [CAPTCHA](/sdk/captcha) - solving challenges
* [AI Providers](/sdk/ai-providers) - bring your own model keys