Communitygithub.com

vercel-labs/vercel-sandbox

Vercel SandboxのマイクロVM内でagent-browser + Chromeを実行し、Vercelにデプロイされたあらゆるアプリからブラウザ自動化を実現します。

vercel-sandbox とは?

このスキルは、Vercel SandboxのエフェメラルなマイクロVM上でヘッドレスChromeとagent-browserを実行し、ブラウザ自動化を可能にします。VercelにデプロイされたNext.js、SvelteKit、Nuxt、Remix、Astroなどのあらゆるフレームワークから利用でき、Linux VMがオンデマンドで起動し、ブラウザコマンドを実行した後に自動でシャットダウンします。主なユースケースは、Vercelアプリ内でのブラウザ自動化、バイナリサイズ制限なしでのヘッドレスChrome実行、コマンド間でのブラウザセッションの永続化、エフェメラルな隔離ブラウザ環境の作成です。Sandboxスナップショット機能により、起動時間をサブ秒に短縮でき、依存関係のインストールを事前に済ませたVMイメージから高速起動が可能です。認証はVercelデプロイ時には自動的にOIDCを通じて行われ、ローカル開発時には環境変数でトークンを設定します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/vercel-labs/agent-browser/tree/main/skill-data/vercel-sandbox

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Vercel Sandboxを使ったブラウザ自動化

エフェメラルなVercel SandboxマイクロVM内でagent-browser + ヘッドレスChromeを実行します。Linux VMがオンデマンドで起動し、ブラウザコマンドを実行してシャットダウンします。Vercelにデプロイされたあらゆるフレームワーク(Next.js、SvelteKit、Nuxt、Remix、Astroなど)で動作します。

依存関係

pnpm add @agent-browser/sandbox @vercel/sandbox

Sandbox VMには、Chromiumのシステム依存関係とagent-browser自体が必要です。@agent-browser/sandboxヘルパーは、新しいサンドボックスにはデフォルトでこれらをインストールし、サブ秒起動のためにサンドボックススナップショット(下記参照)を利用します。サンドボックスイメージに既にChromiumの必要なライブラリが含まれている場合にのみ、installSystemDependencies: falseを渡してください。

コアパターン

import {
  createAgentBrowserSnapshot,
  runAgentBrowserCommand,
  withAgentBrowserSandbox,
  type VercelSandboxSession,
} from "@agent-browser/sandbox/vercel";

async function withBrowser<T>(
  fn: (sandbox: VercelSandboxSession) => Promise<T>,
): Promise<T> {
  return withAgentBrowserSandbox(fn);
}

スクリーンショット

screenshot --jsonコマンドはファイルに保存し、パスを返します。ファイルをbase64として読み戻します:

export async function screenshotUrl(url: string) {
  return withBrowser(async (sandbox) => {
    await runAgentBrowserCommand(sandbox, ["open", url]);

    const titleResult = await runAgentBrowserCommand<{ data?: { title?: string } }>(sandbox, [
      "get", "title",
    ]);
    const title = titleResult.json?.data?.title || url;

    const ssResult = await runAgentBrowserCommand<{ data?: { path?: string } }>(sandbox, [
      "screenshot",
    ]);
    const ssPath = ssResult.json?.data?.path;
    if (!ssPath) throw new Error("スクリーンショットがファイルパスを返しませんでした。");
    const b64Result = await sandbox.runCommand("base64", ["-w", "0", ssPath]);
    const screenshot = (await b64Result.stdout()).trim();

    await runAgentBrowserCommand(sandbox, ["close"], { json: false });

    return { title, screenshot };
  });
}

アクセシビリティスナップショット

export async function snapshotUrl(url: string) {
  return withBrowser(async (sandbox) => {
    await runAgentBrowserCommand(sandbox, ["open", url]);

    const titleResult = await runAgentBrowserCommand<{ data?: { title?: string } }>(sandbox, [
      "get", "title",
    ]);
    const title = titleResult.json?.data?.title || url;

    const snapResult = await runAgentBrowserCommand(sandbox, ["snapshot", "-i", "-c"], {
      json: false,
    });

    await runAgentBrowserCommand(sandbox, ["close"], { json: false });

    return { title, snapshot: snapResult.stdout };
  });
}

マルチステップワークフロー

サンドボックスはコマンド間で永続化されるため、完全な自動化シーケンスを実行できます:

export async function fillAndSubmitForm(
  url: string,
  data: Record<string, string>,
  postSubmitWaitArgs: string[],
) {
  return withBrowser(async (sandbox) => {
    await runAgentBrowserCommand(sandbox, ["open", url]);

    const snapResult = await runAgentBrowserCommand(sandbox, ["snapshot", "-i"], {
      json: false,
    });
    const snapshot = snapResult.stdout;
    // スナップショットを解析して要素参照を見つける...

    for (const [ref, value] of Object.entries(data)) {
      await runAgentBrowserCommand(sandbox, ["fill", ref, value]);
    }

    await runAgentBrowserCommand(sandbox, ["click", "@e5"]);
    // アプリ固有の待機条件を渡す(例: ["--url", "**/checkout/complete"],
    // ["--text", "ありがとう"], ["#confirmation"])
    await runAgentBrowserCommand(sandbox, ["wait", ...postSubmitWaitArgs]);

    const ssResult = await runAgentBrowserCommand<{ data?: { path?: string } }>(sandbox, [
      "screenshot",
    ]);
    const ssPath = ssResult.json?.data?.path;
    if (!ssPath) throw new Error("スクリーンショットがファイルパスを返しませんでした。");
    const b64Result = await sandbox.runCommand("base64", ["-w", "0", ssPath]);
    const screenshot = (await b64Result.stdout()).trim();

    await runAgentBrowserCommand(sandbox, ["close"], { json: false });

    return { screenshot };
  });
}

サンドボックススナップショット(高速起動)

サンドボックススナップショットは、システム依存関係 + agent-browser + Chromiumが既にインストールされたVercel Sandboxの保存済みVMイメージです。Dockerイメージのように考えてください: 毎回依存関係をゼロからインストールする代わりに、サンドボックスは事前に構築されたイメージから起動します。

これはagent-browserのアクセシビリティスナップショット機能(agent-browser snapshot)とは無関係であり、ページのアクセシビリティツリーをダンプするものです。サンドボックススナップショットは、高速なVM起動のためのVercelインフラストラクチャの概念です。

サンドボックススナップショットがない場合、各実行はシステム依存関係 + agent-browser + Chromiumをインストールします(約30秒)。スナップショットがある場合、起動はサブ秒になります。

サンドボックススナップショットの作成

スナップショットには、システム依存関係(dnf経由)、agent-browser、Chromiumが含まれている必要があります:

const snapshotId = await createAgentBrowserSnapshot();

これを一度実行し、その後環境変数を設定します:

AGENT_BROWSER_SNAPSHOT_ID=snap_xxxxxxxxxxxx

デモアプリでヘルパースクリプトが利用可能です:

npx tsx examples/environments/scripts/create-snapshot.ts

Sandboxパターンを使用する本番環境デプロイメントに推奨されます。

認証

Vercelデプロイメントでは、Sandbox SDKはOIDCを介して自動的に認証されます。ローカル開発または明示的な制御の場合は、以下を設定してください:

VERCEL_TOKEN=<パーソナルアクセストークン>
VERCEL_TEAM_ID=<チームID>
VERCEL_PROJECT_ID=<プロジェクトID>

これらはSandbox.create()呼び出しに展開されます。存在しない場合、SDKはVERCEL_OIDC_TOKENにフォールバックします(Vercel上では自動)。

スケジュールワークフロー(Cron)

Vercel Cron Jobsと組み合わせて、定期的なブラウザタスクを実行できます:

// app/api/cron/route.ts (またはフレームワークに応じた同等の場所)
export async function GET() {
  const result = await withBrowser(async (sandbox) => {
    await sandbox.runCommand("agent-browser", ["open", "https://example.com/pricing"]);
    const snap = await sandbox.runCommand("agent-browser", ["snapshot", "-i", "-c"]);
    await sandbox.runCommand("agent-browser", ["close"]);
    return await snap.stdout();
  });

  // 結果を処理し、アラートを送信し、データを保存...
  return Response.json({ ok: true, snapshot: result });
}
// vercel.json
{ "crons": [{ "path": "/api/cron", "schedule": "0 9 * * *" }] }

環境変数

変数必須説明
AGENT_BROWSER_SNAPSHOT_IDいいえ(推奨)サブ秒起動のための事前構築済みサンドボックススナップショットID(上記参照)
VERCEL_TOKENいいえVercelパーソナルアクセストークン(ローカル開発用。Vercel上ではOIDCが自動)
VERCEL_TEAM_IDいいえVercelチームID(ローカル開発用)
VERCEL_PROJECT_IDいいえVercelプロジェクトID(ローカル開発用)

フレームワーク例

パターンはフレームワーク間で同一です。唯一の違いはサーバーサイドコードを配置する場所です:

フレームワークサーバーコードの場所
Next.jsサーバーアクション、APIルート、ルートハンドラ
SvelteKit+page.server.ts、+server.ts
Nuxtserver/api/、server/routes/
Remixloader、action関数
Astro.astro frontmatter、APIルート

例

agent-browserリポジトリのexamples/environments/を参照してください。Vercel Sandboxパターンを使用した実用的なアプリがあり、サンドボックススナップショット作成スクリプト、ストリーミング進行状況UI、レート制限などが含まれています。

Individual skills in this repo

This repo contains 8 individual skills — each has its own dedicated page.

agent-browser

Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to

vercel-labs/agentcore

Run agent-browser on AWS Bedrock AgentCore cloud browsers. Use when the user wants to use AgentCore, run browser automation on AWS, use a cloud browser with AWS credentials, or needs a managed browser session backed by AWS infrastructure. Triggers include "use agentcore", "run on AWS", "cloud browser with AWS", "bedrock browser", "agentcore session", or any task requiring AWS-hosted browser automation.

vercel-labs/derive-client

Reverse-engineer a website's internal API by recording browser traffic into a HAR file, then generate a standalone client or CLI that calls the endpoints directly, with no browser needed after the first recording. Use when asked to "derive a client", "build a CLI for <site>", "reverse engineer this site's API", "record network requests", "turn this site into an API", or when the same site will be automated repeatedly and direct HTTP calls would beat driving the browser every time.

vercel-labs/dogfood

Systematically explore and test a web application to find bugs, UX issues, and other problems. Use when asked to "dogfood", "QA", "exploratory test", "find issues", "bug hunt", "test this app/site/platform", or review the quality of a web application. Produces a structured report with full reproduction evidence -- step-by-step screenshots, repro videos, and detailed repro steps for every issue -- so findings can be handed directly to the responsible teams.

vercel-labs/electron

Automate Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify, etc.) using agent-browser via Chrome DevTools Protocol. Use when the user needs to interact with an Electron app, automate a desktop app, connect to a running app, control a native app, or test an Electron application. Triggers include "automate Slack app", "control VS Code", "interact with Discord app", "test this Electron app", "connect to desktop app", or any task requiring automation of a native Electron application.

vercel-labs/protected-vercel-deployments

Access and test Vercel deployments protected by Vercel Authentication, SSO, or Deployment Protection with agent-browser. Use when a preview or production URL redirects to a Vercel login page, returns a protection 401 or 403, or needs short-lived Trusted Sources OIDC authentication instead of a static bypass secret or public exception.

vercel-labs/slack

Interact with Slack workspaces using browser automation. Use when the user needs to check unread channels, navigate Slack, send messages, extract data, find information, search conversations, or automate any Slack task. Triggers include "check my Slack", "what channels have unreads", "send a message to", "search Slack for", "extract from Slack", "find who said", or any task requiring programmatic Slack interaction.

vercel-labs/webmcp-gen

Build and validate experimental WebMCP tools for an existing web page. Use when an agent needs to expose a site's real workflows as page tools, create webmcp.init.js, define deterministic checks, or compare WebMCP with accessibility-tree automation.

関連スキル