Communitygithub.com

vercel-labs/vercel-sandbox

Exécutez agent-browser + Chrome dans des microVM Vercel Sandbox pour l'automatisation de navigateur depuis n'importe quelle application déployée sur Vercel.

Qu'est-ce que vercel-sandbox ?

Cette compétence permet d'exécuter agent-browser avec Chrome headless dans des microVM éphémères Vercel Sandbox. Contrairement aux environnements serverless classiques limités en taille de binaire, elle offre la puissance d'un navigateur complet sans restriction. Idéale pour les développeurs utilisant Next.js, SvelteKit, Nuxt, Remix ou Astro, elle permet des sessions persistantes entre les commandes, des environnements isolés, et un démarrage quasi instantané grâce aux snapshots de sandbox. L'authentification est automatique sur Vercel via OIDC, et les workflows peuvent être programmés avec les Cron Jobs Vercel. Les cas d'usage incluent les captures d'écran de pages, l'analyse d'accessibilité, le remplissage de formulaires et l'automatisation multi-étapes.

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

Demander à votre IA préférée

Ouvre une nouvelle conversation avec cette compétence d'agent déjà préchargée.

Documentation

Automatisation de navigateur avec Vercel Sandbox

Exécutez agent-browser + Chrome headless dans des microVM Vercel Sandbox éphémères. Une VM Linux est lancée à la demande, exécute les commandes du navigateur, puis s'arrête. Fonctionne avec n'importe quel framework déployé sur Vercel (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.).

Dépendances

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

La VM Sandbox a besoin des dépendances système pour Chromium ainsi que d'agent-browser lui-même. Les helpers @agent-browser/sandbox les installent par défaut pour les sandbox fraîches et utilisent des snapshots de sandbox (ci-dessous) pour un démarrage inférieur à la seconde. Passez installSystemDependencies: false uniquement si l'image du sandbox fournit déjà les bibliothèques requises par Chromium.

Pattern principal

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);
}

Capture d'écran

La commande screenshot --json enregistre dans un fichier et renvoie le chemin. Relisez le fichier en 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("La capture d'écran n'a pas renvoyé de chemin de fichier.");
    const b64Result = await sandbox.runCommand("base64", ["-w", "0", ssPath]);
    const screenshot = (await b64Result.stdout()).trim();

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

    return { title, screenshot };
  });
}

Snapshot d'accessibilité

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 };
  });
}

Workflows multi-étapes

Le sandbox persiste entre les commandes, vous pouvez donc exécuter des séquences d'automatisation complètes :

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;
    // Analyser le snapshot pour trouver les références des éléments...

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

    await runAgentBrowserCommand(sandbox, ["click", "@e5"]);
    // Passez une attente spécifique à l'application, comme ["--url", "**/checkout/complete"],
    // ["--text", "Merci"], ou ["#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("La capture d'écran n'a pas renvoyé de chemin de fichier.");
    const b64Result = await sandbox.runCommand("base64", ["-w", "0", ssPath]);
    const screenshot = (await b64Result.stdout()).trim();

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

    return { screenshot };
  });
}

Snapshots de Sandbox (Démarrage rapide)

Un snapshot de sandbox est une image VM sauvegardée d'un Vercel Sandbox avec les dépendances système + agent-browser + Chromium déjà installés. Considérez-le comme une image Docker : au lieu d'installer les dépendances à partir de zéro à chaque fois, le sandbox démarre à partir de l'image pré-construite.

Ceci n'est pas lié à la fonctionnalité de snapshot d'accessibilité d'agent-browser (agent-browser snapshot), qui extrait l'arbre d'accessibilité d'une page. Un snapshot de sandbox est un concept d'infrastructure Vercel pour un démarrage rapide de VM.

Sans snapshot de sandbox, chaque exécution installe les dépendances système + agent-browser + Chromium (~30s). Avec un snapshot, le démarrage est inférieur à la seconde.

Création d'un snapshot de sandbox

Le snapshot doit inclure les dépendances système (via dnf), agent-browser et Chromium :

const snapshotId = await createAgentBrowserSnapshot();

Exécutez-le une fois, puis définissez la variable d'environnement :

AGENT_BROWSER_SNAPSHOT_ID=snap_xxxxxxxxxxxx

Un script d'aide est disponible dans l'application de démonstration :

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

Recommandé pour tout déploiement en production utilisant le pattern Sandbox.

Authentification

Sur les déploiements Vercel, le SDK Sandbox s'authentifie automatiquement via OIDC. Pour le développement local ou un contrôle explicite, définissez :

VERCEL_TOKEN=<personal-access-token>
VERCEL_TEAM_ID=<team-id>
VERCEL_PROJECT_ID=<project-id>

Ces valeurs sont passées aux appels Sandbox.create(). En leur absence, le SDK utilise VERCEL_OIDC_TOKEN (automatique sur Vercel).

Workflows planifiés (Cron)

Combinez avec les Cron Jobs Vercel pour des tâches de navigateur récurrentes :

// app/api/cron/route.ts  (ou équivalent dans votre framework)
export async function GET() {
  const result = await withBrowser(async (sandbox) => {
    await sandbox.runCommand("agent-browser", ["open", "https://exemple.com/tarifs"]);
    const snap = await sandbox.runCommand("agent-browser", ["snapshot", "-i", "-c"]);
    await sandbox.runCommand("agent-browser", ["close"]);
    return await snap.stdout();
  });

  // Traiter les résultats, envoyer des alertes, stocker des données...
  return Response.json({ ok: true, snapshot: result });
}
// vercel.json
{ "crons": [{ "path": "/api/cron", "schedule": "0 9 * * *" }] }

Variables d'environnement

VariableRequiseDescription
AGENT_BROWSER_SNAPSHOT_IDNon (mais recommandée)ID du snapshot de sandbox pré-construit pour un démarrage inférieur à la seconde (voir ci-dessus)
VERCEL_TOKENNonJeton d'accès personnel Vercel (pour le développement local ; OIDC est automatique sur Vercel)
VERCEL_TEAM_IDNonID de l'équipe Vercel (pour le développement local)
VERCEL_PROJECT_IDNonID du projet Vercel (pour le développement local)

Exemples par framework

Le pattern fonctionne de manière identique d'un framework à l'autre. La seule différence est l'emplacement du code serveur :

FrameworkEmplacement du code serveur
Next.jsActions serveur, routes API, gestionnaires de route
SvelteKit+page.server.ts, +server.ts
Nuxtserver/api/, server/routes/
RemixFonctions loader, action
AstroFrontmatter .astro, routes API

Exemple

Consultez examples/environments/ dans le dépôt agent-browser pour une application fonctionnelle utilisant le pattern Vercel Sandbox, incluant un script de création de snapshot de sandbox, une interface utilisateur de progression en streaming et une limitation de débit.

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.

Skills associés