
Next.js + Kernel template for running AI-powered browser automations with natural language on Vercel.
This template shows how to:
@onkernel/ai-sdk)Clone the repository:
git clone <your-repo-url>cd nextjs-kernel-template
Install dependencies:
bun install
Set up Kernel:
Get your Kernel API key from one of these sources:
Configure environment variables:
Create a .env file:
touch .env.local
Add your API keys:
KERNEL_API_KEY=your_kernel_api_key_hereOPENAI_API_KEY=your_openai_api_key_here
Run the development server:
bun dev
Open http://localhost:3000 in your browser
app/├── api/│ ├── agent/│ │ └── route.ts # AI agent endpoint with browser automation tool│ ├── create-browser/│ │ └── route.ts # Creates a serverless Kernel browser│ └── delete-browser/│ └── route.ts # Closes browser session├── page.tsx # Main UI with live view and controls├── layout.tsx # Root layout└── globals.css # Global stylescomponents/├── Header.tsx # App header with branding├── StepsOverlay.tsx # Modal showing agent execution steps└── ui/ # shadcn/ui components├── button.tsx├── card.tsx├── textarea.tsx└── ...lib/└── utils.ts # Utility functions
Step 1: Create Browser (app/api/create-browser/route.ts)
import { Kernel } from "@onkernel/sdk";// Initialize Kernel clientconst kernel = new Kernel({ apiKey: process.env.KERNEL_API_KEY });// Create a serverless browser with live viewconst browser = await kernel.browsers.create({stealth: true,headless: false,});// Return browser details to clientreturn {sessionId: browser.session_id,liveViewUrl: browser.browser_live_view_url,cdpWsUrl: browser.cdp_ws_url,};
Step 2: Run AI Agent (app/api/agent/route.ts)
import { openai } from "@ai-sdk/openai";import { playwrightExecuteTool } from "@onkernel/ai-sdk";import { Kernel } from "@onkernel/sdk";import { Experimental_Agent as Agent, stepCountIs } from "ai";// Initialize Kernel instanceconst kernel = new Kernel({ apiKey: process.env.KERNEL_API_KEY });// Initialize the AI agent with GPT-5.1 and Kernel's AI SDK-compatible browser automation toolconst agent = new Agent({model: openai("gpt-5.1"),tools: {playwright_execute: playwrightExecuteTool({client: kernel,sessionId: sessionId,}),},stopWhen: stepCountIs(20),system: `You are a browser automation expert with access to a Playwright execution tool...`,});// Execute the agent with the user's taskconst { text, steps } = await agent.generate({prompt: task, // e.g., "Go to news.ycombinator.com and get the first article title"});
Push to GitHub
Connect to Vercel:
KERNEL_API_KEY and OPENAI_API_KEY)Using Vercel Marketplace Integration:
OPENAI_API_KEY manuallyMake sure to add these environment variables in your Vercel project settings:
KERNEL_API_KEY - Your Kernel API keyOPENAI_API_KEY - Your OpenAI API keyBuilt with Kernel, Vercel AI SDK, and Vercel