### Kernel CLI Quick Start Source: https://github.com/kernel/docs/blob/main/reference/cli.mdx A quick guide to getting started with the Kernel CLI, covering app creation, login, deployment, and invocation. ```bash # 1) Create a new app kernel create # 2) Login kernel login # 3) Deploy your app kernel deploy index.ts # 4) Invoke your app kernel invoke my-app action-name --payload '{"key":"value"}' ``` -------------------------------- ### Complete Hosted UI Example Source: https://github.com/kernel/docs/blob/main/auth/hosted-ui.mdx A full example demonstrating the creation of a connection, starting a login session, redirecting the user, polling for completion, and finally creating an authenticated browser. ```typescript import Kernel from '@onkernel/sdk'; const kernel = new Kernel(); // Create connection const auth = await kernel.auth.connections.create({ domain: 'doordash.com', profile_name: 'doordash-user-123', }); // Start authentication const login = await kernel.auth.connections.login(auth.id); // Send user to hosted page console.log('Login URL:', login.hosted_url); // Poll for completion let state = await kernel.auth.connections.retrieve(auth.id); while (state.flow_status === 'IN_PROGRESS') { await new Promise(r => setTimeout(r, 2000)); state = await kernel.auth.connections.retrieve(auth.id); } if (state.status === 'AUTHENTICATED') { const browser = await kernel.browsers.create({ profile: { name: 'doordash-user-123' }, stealth: true, }); // Navigate to the site—you're already logged in await page.goto('https://doordash.com'); } ``` ```python from kernel import Kernel import asyncio kernel = Kernel() # Create connection auth = await kernel.auth.connections.create( domain="doordash.com", profile_name="doordash-user-123", ) # Start authentication login = await kernel.auth.connections.login(auth.id) # Send user to hosted page print(f"Login URL: {login.hosted_url}") ``` -------------------------------- ### Quick Setup for Gemini Computer Use App Source: https://github.com/kernel/docs/blob/main/integrations/computer-use/gemini.mdx Use this command to create a new project with a pre-configured template for Gemini Computer Use on Kernel. Follow the deploy and invoke guides to run your automation. ```bash kernel create --name my-computer-use-app --language typescript --template gemini-computer-use ``` -------------------------------- ### Install Kernel and Vibium Source: https://github.com/kernel/docs/blob/main/integrations/vibium.mdx Install the Kernel CLI and Vibium using npm or pip. ```bash npm install -g @onkernel/cli vibium ``` ```bash npm install @onkernel/sdk vibium ``` ```bash pip install kernel vibium ``` -------------------------------- ### Install @onkernel/managed-auth-react Source: https://github.com/kernel/docs/blob/main/auth/react.mdx Install the React component library using your preferred package manager. ```bash bun add @onkernel/managed-auth-react # or: npm install @onkernel/managed-auth-react ``` -------------------------------- ### Complete File Download and Read Example Source: https://github.com/kernel/docs/blob/main/browsers/file-io.mdx A full example demonstrating browser creation, Stagehand initialization for downloads, triggering a download, waiting for the file, reading it via Kernel's File I/O, and saving it locally. ```typescript import { Stagehand } from "@browserbasehq/stagehand"; import Kernel from "@onkernel/sdk"; import fs from "fs"; const DOWNLOAD_DIR = "/tmp/downloads"; // Poll listFiles until any file appears in the directory async function waitForFile( kernel: Kernel, sessionId: string, dir: string, timeoutMs = 30_000 ) { const start = Date.now(); while (Date.now() - start < timeoutMs) { const files = await kernel.browsers.fs.listFiles(sessionId, { path: dir }); if (files.length > 0) { return files[0]; } await new Promise((r) => setTimeout(r, 500)); } throw new Error(`No files found in ${dir} after ${timeoutMs}ms`); } async function main() { const kernel = new Kernel(); console.log("Creating browser via Kernel..."); const kernelBrowser = await kernel.browsers.create({ stealth: true, }); console.log(`Kernel Browser Session Started`); console.log(`Session ID: ${kernelBrowser.session_id}`); console.log(`Watch live: ${kernelBrowser.browser_live_view_url}`); // Initialize Stagehand with Kernel's CDP URL and download configuration const stagehand = new Stagehand({ env: "LOCAL", verbose: 1, localBrowserLaunchOptions: { cdpUrl: kernelBrowser.cdp_ws_url, downloadsPath: DOWNLOAD_DIR, acceptDownloads: true, }, }); await stagehand.init(); const page = stagehand.context.pages()[0]; await page.goto("https://browser-tests-alpha.vercel.app/api/download-test"); // Use Stagehand to click the download button await stagehand.act("Click the download file link"); console.log("Download triggered"); // Wait for the file to be fully available via Kernel's File I/O APIs console.log("Waiting for file to appear..."); const downloadedFile = await waitForFile( kernel, kernelBrowser.session_id, DOWNLOAD_DIR ); console.log(`File found: ${downloadedFile.name}`); const remotePath = `${DOWNLOAD_DIR}/${downloadedFile.name}`; console.log(`Reading file from: ${remotePath}`); // Read the file from Kernel browser's filesystem const resp = await kernel.browsers.fs.readFile(kernelBrowser.session_id, { path: remotePath, }); // Save to local filesystem const bytes = await resp.bytes(); fs.mkdirSync("downloads", { recursive: true }); const localPath = `downloads/${downloadedFile.name}`; fs.writeFileSync(localPath, bytes); console.log(`Saved to ${localPath}`); // Clean up await stagehand.close(); await kernel.browsers.deleteByID(kernelBrowser.session_id); console.log("Browser session closed"); } main().catch((err) => { console.error(err); process.exit(1); }); ``` -------------------------------- ### Full example: Acquire, use, and release a browser Source: https://github.com/kernel/docs/blob/main/browsers/pools/overview.mdx This example demonstrates the typical workflow of acquiring a browser from a pool, using it for a task, and then releasing it back to the pool for reuse. ```APIDOC ## Full example This example assumes you've already created a pool named "my-pool". In practice, you'd create pools once (via the SDK, CLI, or dashboard) and then acquire from them repeatedly. ### Acquire, use, and release a browser ```typescript import Kernel from '@onkernel/sdk'; import { chromium } from 'playwright'; const kernel = new Kernel(); // Acquire a browser from an existing pool const kernelBrowser = await kernel.browserPools.acquire("my-pool", {}); try { // Connect via CDP const browser = await chromium.connectOverCDP(kernelBrowser.cdp_ws_url); const context = browser.contexts()[0]; const page = context.pages()[0]; await page.goto('https://example.com'); const title = await page.title(); console.log(title); } finally { // Release back to pool for reuse await kernel.browserPools.release("my-pool", { session_id: kernelBrowser.session_id, }); } ``` ```python import asyncio from kernel import Kernel from playwright.async_api import async_playwright kernel = Kernel() async def main(): # Acquire a browser from an existing pool kernel_browser = kernel.browser_pools.acquire("my-pool") async with async_playwright() as playwright: try: # Connect via CDP browser = await playwright.chromium.connect_over_cdp(kernel_browser.cdp_ws_url) context = browser.contexts[0] page = context.pages[0] await page.goto('https://example.com') title = await page.title() print(title) finally: # Release back to pool for reuse kernel.browser_pools.release( "my-pool", session_id=kernel_browser.session_id, ) asyncio.run(main()) ``` ### Parameters #### Acquire Browser - **pool_name** (string) - Required - The name of the pool to acquire a browser from. - **options** (object) - Optional - Configuration options for acquiring a browser. - **session_id** (string) - Optional - The session ID of the browser to acquire. If not provided, a new browser session will be acquired. #### Release Browser - **pool_name** (string) - Required - The name of the pool to release the browser back to. - **options** (object) - Optional - Configuration options for releasing the browser. - **session_id** (string) - Required - The session ID of the browser to release. - **reuse** (boolean) - Optional - If true, the browser instance is reused. If false, it is destroyed and a fresh one is created. Defaults to true. ``` -------------------------------- ### Install websocat on Linux Source: https://github.com/kernel/docs/blob/main/browsers/ssh.mdx Install the `websocat` utility on Linux by downloading the binary and making it executable. This is a prerequisite for using the `kernel browsers ssh` command. ```bash curl -fsSL https://github.com/vi/websocat/releases/download/v1.14.1/websocat.x86_64-unknown-linux-musl \ -o /usr/local/bin/websocat && chmod +x /usr/local/bin/websocat ``` -------------------------------- ### Install Kernel SDK Source: https://github.com/kernel/docs/blob/main/integrations/browser-use.mdx Install the Kernel SDK using pip. This is the first step to integrate Kernel with your existing Browser Use implementation. ```bash uv add kernel ``` -------------------------------- ### Install Dependencies for Python App Source: https://github.com/kernel/docs/blob/main/reference/cli/create.mdx Set up a Python virtual environment and install project dependencies using `uv`. ```bash uv venv && source .venv/bin/activate && uv sync ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/kernel/docs/blob/main/reference/cli/create.mdx After creating your application, change into the newly created project directory to proceed with setup and deployment. ```bash cd my-app ``` -------------------------------- ### Quick Setup with Computer Use Template Source: https://github.com/kernel/docs/blob/main/integrations/computer-use/anthropic.mdx Use the Kernel CLI to create a new project pre-configured for Computer Use. Choose between TypeScript or Python for your project. ```bash kernel create --name my-computer-use-app --template computer-use ``` -------------------------------- ### Create TypeScript Kernel App with Sample Template Source: https://github.com/kernel/docs/blob/main/reference/cli/create.mdx Scaffold a new TypeScript application using the `sample-app` template. This is useful for getting started with a basic project structure that includes Playwright integration. ```bash kernel create --name my-app --language typescript --template sample-app ``` -------------------------------- ### Install AI SDK and Dependencies Source: https://github.com/kernel/docs/blob/main/integrations/vercel/ai-sdk.mdx Install the @onkernel/ai-sdk package along with its peer dependencies for AI and Kernel SDK. ```bash npm install @onkernel/ai-sdk zod npm install ai @onkernel/sdk ``` -------------------------------- ### Full Browser Pool Example Source: https://github.com/kernel/docs/blob/main/browsers/pools/overview.mdx Demonstrates acquiring a browser from a pool, using it to navigate and get a page title, and then releasing it back to the pool for reuse. Assumes a pool named 'my-pool' already exists. ```typescript import Kernel from '@onkernel/sdk'; import { chromium } from 'playwright'; const kernel = new Kernel(); // Acquire a browser from an existing pool const kernelBrowser = await kernel.browserPools.acquire("my-pool", {}); try { // Connect via CDP const browser = await chromium.connectOverCDP(kernelBrowser.cdp_ws_url); const context = browser.contexts()[0]; const page = context.pages()[0]; await page.goto('https://example.com'); const title = await page.title(); console.log(title); } finally { // Release back to pool for reuse await kernel.browserPools.release("my-pool", { session_id: kernelBrowser.session_id, }); } ``` ```python import asyncio from kernel import Kernel from playwright.async_api import async_playwright kernel = Kernel() async def main(): # Acquire a browser from an existing pool kernel_browser = kernel.browser_pools.acquire("my-pool") async with async_playwright() as playwright: try: # Connect via CDP browser = await playwright.chromium.connect_over_cdp(kernel_browser.cdp_ws_url) context = browser.contexts[0] page = context.pages[0] await page.goto('https://example.com') title = await page.title() print(title) finally: # Release back to pool for reuse kernel.browser_pools.release( "my-pool", session_id=kernel_browser.session_id, ) asyncio.run(main()) ``` -------------------------------- ### Quick Start with Kernel Provider Source: https://github.com/kernel/docs/blob/main/integrations/agent-browser.mdx Use the `-p kernel` flag to enable the Kernel provider. Ensure KERNEL_API_KEY is set. ```bash export KERNEL_API_KEY="your-api-key" agent-browser -p kernel open https://example.com ``` -------------------------------- ### Setup SSH on VM Only Source: https://github.com/kernel/docs/blob/main/browsers/ssh.mdx Install and configure the SSH server on the browser VM without initiating an SSH connection. This command prints the manual connection details, allowing you to connect using your own SSH client. ```bash kernel browsers ssh --setup-only ``` -------------------------------- ### Install Kernel SDK for Node.js Source: https://github.com/kernel/docs/blob/main/apps/develop.mdx Install the Kernel SDK for Javascript/Typescript projects using npm. ```bash npm install @onkernel/sdk ``` -------------------------------- ### Install Kernel CLI Source: https://github.com/kernel/docs/blob/main/reference/cli.mdx Install the Kernel CLI using package managers like Homebrew, pnpm, or npm. ```bash # Using brew brew install onkernel/tap/kernel ``` ```bash # Using pnpm pnpm install -g @onkernel/cli ``` ```bash # Using npm npm install -g @onkernel/cli ``` -------------------------------- ### Install Kernel SDK for Python Source: https://github.com/kernel/docs/blob/main/apps/develop.mdx Install the Kernel SDK for Python projects using pip. ```bash uv pip install kernel ``` -------------------------------- ### Install websocat on macOS Source: https://github.com/kernel/docs/blob/main/browsers/ssh.mdx Install the `websocat` utility on macOS using Homebrew. This is a prerequisite for using the `kernel browsers ssh` command. ```bash brew install websocat ``` -------------------------------- ### Example tasks for Claude Agent SDK Source: https://github.com/kernel/docs/blob/main/integrations/claude-agent-sdk.mdx Examples of tasks that can be performed by the Claude Agent SDK, including fetching data, searching, and extracting information from web pages. ```bash # Get top Hacker News stories "Go to https://news.ycombinator.com and tell me the top 3 stories" # Search for something "Go to duckduckgo.com and search for 'Kernel browser automation'" # Extract data from a page "Go to https://github.com/trending and list the top 5 trending repositories" ``` -------------------------------- ### Successful Deployment CLI Output Source: https://github.com/kernel/docs/blob/main/apps/deploy.mdx Example output indicating a successful app deployment and providing information on how to invoke the deployed app. ```bash # Successful deployment CLI output SUCCESS Compressed files SUCCESS Deployment successful SUCCESS App "my_app.ts" deployed with action(s): [my-action] INFO Invoke with: kernel invoke my-app my-action --payload '{...}' SUCCESS Total deployment time: 2.78s ``` -------------------------------- ### Show command-specific usage Source: https://github.com/kernel/docs/blob/main/reference/cli/auth.mdx Get detailed usage information and options for a specific command. ```bash kernel --help ``` -------------------------------- ### Create a Residential Proxy Source: https://github.com/kernel/docs/blob/main/proxies/residential.mdx This example demonstrates how to create a residential proxy targeting a specific country. You can also specify state, city, or ASN for more granular control. ```APIDOC ## Create a Residential Proxy ### Description Creates a residential proxy with specified targeting options. ### Method `kernel.proxies.create(options)` ### Parameters #### Request Body - **`type`** (string) - Required - The type of proxy, must be 'residential'. - **`name`** (string) - Required - A unique name for the proxy. - **`config`** (object) - Required - Configuration object for targeting. - **`country`** (string) - Required - ISO 3166 country code. - **`state`** (string) - Optional - Two-letter state code (US only). - **`city`** (string) - Optional - City name (lowercase, no spaces, e.g., `sanfrancisco`). Conflicts with state. - **`zip`** (string) - Optional - US ZIP code (5 digits). Cannot be combined with `city` or `state`. - **`asn`** (string) - Optional - Autonomous System Number. Conflicts with city and state. - **`bypass_hosts`** (array) - Optional - Array of hostnames that bypass the proxy (max 100 entries). ### Request Example (Typescript/Javascript) ```typescript const proxy = await kernel.proxies.create({ type: 'residential', name: 'my-us-residential', config: { country: 'US' } }); ``` ### Request Example (Python) ```python proxy = kernel.proxies.create( type='residential', name='my-us-residential', config={ 'country': 'US' } ) ``` ### Response #### Success Response (200) - **`id`** (string) - The unique identifier of the created proxy. - **`type`** (string) - The type of the proxy ('residential'). - **`name`** (string) - The name of the proxy. - **`config`** (object) - The configuration used for the proxy. ### Response Example ```json { "id": "proxy_xxxxxxxxxxxx", "type": "residential", "name": "my-us-residential", "config": { "country": "US" } } ``` ``` -------------------------------- ### Quick Setup for OpenAGI Computer Use Source: https://github.com/kernel/docs/blob/main/integrations/computer-use/openagi.mdx Use the Kernel CLI to quickly set up a pre-configured OpenAGI app with AsyncDefaultAgent and TaskerAgent implementations. Navigate to the created directory and deploy the main Python file. ```bash kernel create --template openagi-computer-use --language python cd kernel deploy main.py --env-file .env ``` -------------------------------- ### Kernel App with Laminar Tracing (Python) Source: https://github.com/kernel/docs/blob/main/integrations/laminar.mdx This Python example shows how to integrate Laminar tracing with Kernel for browser automation. It covers initializing Laminar, connecting to a Kernel-managed browser via Playwright, performing web automation, and utilizing Kernel's tool calls for processing and mouse interaction. Ensure the Kernel SDK and Playwright are installed. ```python from lmnr import Laminar from playwright.async_api import async_playwright from kernel import App, Kernel, KernelContext # Initialize Laminar Laminar.initialize() kernel_client = Kernel() app = App("my-app-name") @app.action(name="my-action") async def run_automation(ctx: KernelContext): # Connect Playwright to Kernel's browser async with async_playwright() as p: kernel_browser = kernel_client.browsers.create( invocation_id=ctx.invocation_id ) browser = await p.chromium.connect_over_cdp(kernel_browser.cdp_ws_url) context = ( browser.contexts[0] if browser.contexts else await browser.new_context() ) page = context.pages[0] if context.pages else await context.new_page() # Your automation code await page.goto('https://www.duckduckgo.com/') await page.wait_for_timeout(2000) await page.goto('https://www.github.com/trending') await page.wait_for_timeout(2000) # Extract all trending repos trending_repos = await page.locator("h2 a.Link").evaluate_all(r""" (repos) => repos.map((repo) => repo.textContent.trim().replace(/[ \s]/g, '') ) """) print('Trending repos:', trending_repos) # Process tool call kernel_client.browsers.process.exec( id=kernel_browser.session_id, command="ls", args=["-la"], ) # Computer tool call kernel_client.browsers.computer.move_mouse( id=kernel_browser.session_id, x=100, y=100, ) # Wait for 3 seconds await page.wait_for_timeout(3000) # Clean up the browser await browser.close() # Delete the browser for those who left open the Kernel live view url kernel_client.browsers.delete_by_id(kernel_browser.session_id) print("Done") ``` -------------------------------- ### Install Claude Code Source: https://github.com/kernel/docs/blob/main/integrations/claude-agent-sdk.mdx Install Claude Code, a prerequisite for the Claude Agent SDK, using package managers or a script. Note that Kernel automatically installs Claude Code on remote infrastructure during deployment. ```bash # Homebrew (macOS) brew install --cask claude-code # pnpm (cross-platform) pnpm add -g @anthropic-ai/claude-code # macOS/Linux/WSL curl -fsSL https://claude.ai/install.sh | bash ``` -------------------------------- ### Set Up and Save Browser Profiles Source: https://github.com/kernel/docs/blob/main/reference/mcp-server.mdx Utilize the `setup_profile` tool to create and configure browser profiles for authentication. The `delete_browser` tool can be used to save the profile after setup is complete. ```bash [Uses setup_profile tool] ``` ```bash [Uses delete_browser tool to save profile] ``` -------------------------------- ### Install Dependencies for TypeScript App Source: https://github.com/kernel/docs/blob/main/reference/cli/create.mdx Install the necessary Node.js packages for a TypeScript Kernel application. ```bash npm install ``` -------------------------------- ### Deploy App from Local Directory Source: https://github.com/kernel/docs/blob/main/apps/deploy.mdx Use this command from your project's root directory to deploy your app. Specify the entrypoint file name. ```bash kernel deploy ``` -------------------------------- ### Start a Login Session Source: https://github.com/kernel/docs/blob/main/auth/hosted-ui.mdx Starts a Managed Auth Session to obtain the hosted login URL. ```APIDOC ## Start Login Session ### Description Initiates a Managed Auth Session to generate a hosted login URL for user authentication. ### Method `kernel.auth.connections.login(connection_id: string)` ### Parameters #### Path Parameters - **connection_id** (string) - Required - The ID of the Managed Auth Connection. ### Request Example ```typescript const login = await kernel.auth.connections.login(auth.id); ``` ```python login = await kernel.auth.connections.login(auth.id) ``` ### Response #### Success Response (200) - **hosted_url** (string) - The URL of the hosted login page where the user can enter credentials. ### Response Example ```json { "hosted_url": "https://hosted.kernel.app/login?connectionId=conn_abc123" } ``` ``` -------------------------------- ### Example Viewport Configurations Source: https://github.com/kernel/docs/blob/main/browsers/viewport.mdx Demonstrates creating browser instances with various supported viewport configurations, including explicit refresh rates and auto-determined rates for resolutions like Full HD, QHD, and XGA. ```typescript // Full HD (1920x1080) at 25Hz - explicit refresh rate const fullHD = await kernel.browsers.create({ viewport: { width: 1920, height: 1080, refresh_rate: 25 } }); // Full HD (1920x1080) - auto-determined 25Hz (Default configuration) const fullHDAuto = await kernel.browsers.create({ viewport: { width: 1920, height: 1080 } }); // QHD (2560x1440) - auto-determined 10Hz // Note: May affect live view responsiveness const qhd = await kernel.browsers.create({ viewport: { width: 2560, height: 1440 } }); // XGA (1024x768) - auto-determined 60Hz const xga = await kernel.browsers.create({ viewport: { width: 1024, height: 768 } }); // WUXGA (1920x1200) at 25Hz - explicit refresh rate const wuxga = await kernel.browsers.create({ viewport: { width: 1920, height: 1200, refresh_rate: 25 } }); ``` ```python # Full HD (1920x1080) at 25Hz - explicit refresh rate full_hd = kernel.browsers.create( viewport={ "width": 1920, "height": 1080, "refresh_rate": 25 } ) # Full HD (1920x1080) - auto-determined 25Hz (Default configuration) full_hd_auto = kernel.browsers.create( viewport={ "width": 1920, "height": 1080 } ) # QHD (2560x1440) - auto-determined 10Hz ``` -------------------------------- ### Verify Kernel CLI Installation Source: https://github.com/kernel/docs/blob/main/reference/cli.mdx Check if the Kernel CLI is installed and accessible by verifying its path and version. ```bash which kernel kernel --version ``` -------------------------------- ### Unpacked Extension Example Source: https://github.com/kernel/docs/blob/main/browsers/extensions.mdx An example of an unpacked Chrome extension, including its content script and manifest file. ```javascript document.body.innerHTML = document.body.innerHTML.replace(/AI/g, "A1"); ``` ```json { "manifest_version": 3, "version": "1.0", "name": "AI to A1", "description": "Replace AI with A1", "content_scripts": [ { "matches": [ "https://*/*" ], "js": [ "content-script.js" ] } ] } ``` -------------------------------- ### Full Kernel Browser Lifecycle Example Source: https://github.com/kernel/docs/blob/main/browsers/create-a-browser.mdx Demonstrates the complete lifecycle of a Kernel browser, from creation and connection to usage and cleanup. It accesses the default context and page, navigates to a URL, and handles potential errors. ```typescript import Kernel from '@onkernel/sdk'; import { chromium } from 'playwright'; const kernel = new Kernel(); const kernelBrowser = await kernel.browsers.create(); const browser = await chromium.connectOverCDP(kernelBrowser.cdp_ws_url); try { const context = browser.contexts()[0] || (await browser.newContext()); const page = context.pages()[0] || (await context.newPage()); await page.goto('https://www.onkernel.com'); const title = await page.title(); } catch (error) { console.error(error); } finally { await browser.close(); await kernel.browsers.deleteByID(kernelBrowser.session_id); } ``` ```python from kernel import Kernel from playwright.async_api import async_playwright kernel = Kernel() kernel_browser = kernel.browsers.create() async with async_playwright() as playwright: browser = await playwright.chromium.connect_over_cdp(kernel_browser.cdp_ws_url) try: context = browser.contexts[0] if browser.contexts else await browser.new_context() page = context.pages[0] if context.pages else await context.new_page() await page.goto('https://www.onkernel.com') title = await page.title() except Exception as e: print(e) finally: await browser.close() await kernel.browsers.delete_by_id(kernel_browser.session_id) ``` -------------------------------- ### Initialize Kernel and Notte Clients Source: https://github.com/kernel/docs/blob/main/integrations/notte.mdx Initialize the Kernel client and the Notte client with your API key. Then, create a cloud browser session using Kernel. ```python from kernel import Kernel from notte_sdk import NotteClient # Initialize clients kernel = Kernel() notte_client = NotteClient(api_key="your-notte-api-key") # Create a browser on Kernel kernel_browser = kernel.browsers.create() ``` -------------------------------- ### Create Kernel App with Browser Use Template Source: https://github.com/kernel/docs/blob/main/integrations/browser-use.mdx Quickly set up a Browser Use integration by creating a new Kernel app using the provided template. This pre-configures the necessary components. ```bash kernel create --name my-browser-use-app --language python --template browser-use ``` -------------------------------- ### Scaffold a Project with a Template Source: https://github.com/kernel/docs/blob/main/index.mdx Use this command to create a new project from a predefined template. This is the first step in setting up your agent project. ```bash kernel create --template computer-use ``` -------------------------------- ### Install Laminar and Kernel Packages Source: https://github.com/kernel/docs/blob/main/integrations/laminar.mdx Install the necessary packages for Laminar and Kernel integration using npm or uv pip. ```bash npm install @lmnr-ai/lmnr @onkernel/sdk ``` ```bash uv pip install --upgrade 'lmnr[all]' kernel ``` -------------------------------- ### Deploy App from GitHub Repository Source: https://github.com/kernel/docs/blob/main/apps/deploy.mdx Deploy directly from a GitHub repository without cloning. Provide the repository URL, branch/tag/commit reference, and the entrypoint path. Optional flags include a subdirectory path, GitHub token for private repos, environment variables, and force deployment. ```bash kernel deploy github \ --url https://github.com// \ --ref \ --entrypoint \ [--path ] \ [--github-token ] \ [--env KEY=value ...] \ [--env-file .env] \ [--version latest] \ [--force] ``` -------------------------------- ### Create Magnitude App with Kernel Template Source: https://github.com/kernel/docs/blob/main/integrations/magnitude.mdx Quickly set up a Magnitude integration with Kernel using the provided app template. This command creates a new project with pre-configured settings. ```bash kernel create --name my-magnitude-app --language typescript --template magnitude ``` -------------------------------- ### Run Docs Site Locally Source: https://github.com/kernel/docs/blob/main/AGENTS.md Use this command to serve the documentation site locally for preview and validation. It automatically handles port conflicts. ```bash mintlify dev ``` -------------------------------- ### Start and Stop Browser Recording Source: https://github.com/kernel/docs/blob/main/browsers/replays.mdx Initiates a replay recording for a browser session and stops it afterward. Ensure a browser session is active before starting a recording. ```typescript import Kernel from '@onkernel/sdk'; const kernel = new Kernel(); const kernelBrowser = await kernel.browsers.create(); const replay = await kernel.browsers.replays.start(kernelBrowser.session_id); console.log(`Recording started with ID: ${replay.replay_id}`); // Perform some automation... await kernel.browsers.replays.stop(replay.replay_id, { id: kernelBrowser.session_id }); console.log('Recording stopped and processing'); ``` ```python from kernel import Kernel kernel = Kernel() kernel_browser = kernel.browsers.create() replay = kernel.browsers.replays.start(kernel_browser.session_id) print(f"Recording started with ID: {replay.replay_id}") # Perform some automation... kernel.browsers.replays.stop(replay_id=replay.replay_id, id=kernel_browser.session_id) print("Recording stopped and processing") ``` -------------------------------- ### Create a Kernel App in Python Source: https://github.com/kernel/docs/blob/main/apps/develop.mdx Instantiate the Kernel SDK and create a new app instance with a specified name. ```python from kernel import Kernel, App, KernelContext kernel = Kernel() app = App("my-app-name") ``` -------------------------------- ### Start Replay Recording Source: https://github.com/kernel/docs/blob/main/reference/cli/browsers.mdx Starts recording a replay for a browser session. Allows setting framerate, maximum duration, and output format. Supports JSON output. ```APIDOC ## kernel browsers replays start Start recording a replay. | Flag | Description | |------|-------------| | `--framerate ` | Recording framerate in frames per second. | | `--max-duration ` | Maximum recording duration. | | `--output json`, `-o json` | Output raw JSON object. | ``` -------------------------------- ### Install MCP for Cursor Source: https://github.com/kernel/docs/blob/main/reference/cli/mcp.mdx Installs the Kernel MCP server configuration for the Cursor editor. This command automatically configures the MCP server in Cursor's settings file. ```bash kernel mcp install --target cursor ``` -------------------------------- ### Download File and Read with Kernel Source: https://github.com/kernel/docs/blob/main/browsers/file-io.mdx Demonstrates downloading a file from a webpage, handling download events, and then reading the downloaded file using Kernel's File I/O APIs. Requires setting up CDP download behavior and event listeners. ```python async def main(): kernel_browser = kernel.browsers.create() print("Kernel browser live view url:", kernel_browser.browser_live_view_url) async with async_playwright() as playwright: browser = await playwright.chromium.connect_over_cdp(kernel_browser.cdp_ws_url) context = browser.contexts[0] page = context.pages[0] if len(context.pages) > 0 else await context.new_page() cdp_session = await context.new_cdp_session(page) await cdp_session.send( "Browser.setDownloadBehavior", { "behavior": "default", "eventsEnabled": True, }, ) download_completed = asyncio.Event() download_file_path: str | None = None download_state: str | None = None def _on_download_begin(event): print(f"Download started: {event.get('suggestedFilename', 'unknown')}") def _on_download_progress(event): nonlocal download_state, download_file_path if event.get("state") in ["completed", "canceled"]: download_state = event.get("state") download_file_path = event.get("filePath") download_completed.set() cdp_session.on("Browser.downloadWillBegin", _on_download_begin) cdp_session.on("Browser.downloadProgress", _on_download_progress) print("Navigating to download test page") await page.goto("https://browser-tests-alpha.vercel.app/api/download-test") await page.get_by_role("link", name="Download File").click() try: await asyncio.wait_for(download_completed.wait(), timeout=10) print("Download completed") except asyncio.TimeoutError: print("Download timed out after 10 seconds") raise if download_state == "canceled": raise RuntimeError("Download was canceled") if not download_file_path: raise RuntimeError("Unable to determine download file path") # Wait for the file to be available via Kernel's File I/O APIs print(f"Waiting for file: {download_file_path}") await wait_for_file(kernel_browser.session_id, download_file_path) resp = kernel.browsers.fs.read_file( kernel_browser.session_id, path=download_file_path ) local_path = f"./downloads/{Path(download_file_path).name}" os.makedirs("./downloads", exist_ok=True) resp.write_to_file(local_path) print(f"Saved to {local_path}") kernel.browsers.delete_by_id(kernel_browser.session_id) print("Kernel browser deleted successfully.") if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Create Browser with Web Bot Auth Extension (CLI) Source: https://github.com/kernel/docs/blob/main/browsers/bot-detection/web-bot-auth.mdx Create a browser with the web-bot-auth extension using the Kernel CLI. The command outputs the browser ID and live view URL. ```bash # Create a browser with the web-bot-auth extension kernel browsers create --extension my-web-bot-auth # The command outputs the browser ID and live view URL # Open the live view URL in your browser, then navigate to: # https://http-message-signatures-example.research.cloudflare.com/ ``` -------------------------------- ### Install Kernel MCP Extension for Zed Source: https://github.com/kernel/docs/blob/main/reference/mcp-server.mdx Install the Kernel MCP extension for Zed using the Kernel CLI. This is the recommended method for integrating Kernel's cloud-based browsers. ```bash kernel mcp install --target zed ``` -------------------------------- ### Initialize Kernel and Create Browser Source: https://github.com/kernel/docs/blob/main/integrations/stagehand.mdx Import necessary libraries and initialize a cloud browser session with Kernel. This sets up the browser environment for Stagehand. ```typescript import { Stagehand } from "@browserbasehq/stagehand"; import Kernel from '@onkernel/sdk'; import { z } from "zod"; const kernel = new Kernel(); const kernelBrowser = await kernel.browsers.create({ stealth: true }); console.log("Live view url: ", kernelBrowser.browser_live_view_url); ``` -------------------------------- ### Install Kernel MCP Extension for Windsurf Source: https://github.com/kernel/docs/blob/main/reference/mcp-server.mdx Install the Kernel MCP extension for Windsurf using the Kernel CLI. This is the recommended method for integrating Kernel's cloud-based browsers. ```bash kernel mcp install --target windsurf ``` -------------------------------- ### Initialize Kernel and Create Browser Source: https://github.com/kernel/docs/blob/main/integrations/magnitude.mdx Initialize the Kernel SDK and create a cloud browser session. This session will be used by Magnitude. Ensure you have the necessary imports. ```typescript import { startBrowserAgent } from "magnitude-core"; import Kernel from '@onkernel/sdk'; import z from 'zod'; const kernel = new Kernel(); const kernelBrowser = await kernel.browsers.create({ stealth: true, }); console.log(`Live view url: ${kernelBrowser.browser_live_view_url}`); ``` -------------------------------- ### Install Kernel MCP for Claude Code CLI Source: https://github.com/kernel/docs/blob/main/reference/mcp-server.mdx Use the Kernel CLI to automatically configure MCP for the Claude Code CLI. After installation, run '/mcp' in the REPL to authenticate. ```bash kernel mcp install --target claude-code # Then in the REPL run once to authenticate: /mcp ``` -------------------------------- ### Create Browser with Extension (CLI) Source: https://github.com/kernel/docs/blob/main/browsers/extensions.mdx Command to create a new browser instance with a specified extension loaded using the Kernel CLI. ```bash kernel browsers create --extension my-extension ``` -------------------------------- ### Install MCP for Claude Desktop Source: https://github.com/kernel/docs/blob/main/reference/cli/mcp.mdx Installs the Kernel MCP server configuration for the Claude Desktop application. This command automatically configures the MCP server in the app's settings file. ```bash kernel mcp install --target claude ``` -------------------------------- ### Integrate Browser Use with Laminar and Kernel Source: https://github.com/kernel/docs/blob/main/integrations/laminar.mdx This example shows how to integrate the Browser Use framework with Laminar and Kernel. It initializes Laminar, Kernel, and a Browser Use agent to perform tasks like navigating websites and extracting job URLs. ```python import os import asyncio from lmnr import Laminar, observe from browser_use import Agent, Browser, ChatOpenAI from kernel import Kernel # Initialize Laminar Laminar.initialize(project_api_key=os.environ["LMNR_PROJECT_API_KEY"]) @observe() async def main(): # Initialize Kernel and create a browser client = Kernel() kernel_browser = client.browsers.create(stealth=True, viewport={'width': 1920, 'height': 1080}) print(f"Live view url: {kernel_browser.browser_live_view_url}") # Configure Browser Use with Kernel's CDP URL browser = Browser( cdp_url=kernel_browser.cdp_ws_url, headless=False, window_size={'width': 1920, 'height': 1080}, viewport={'width': 1920, 'height': 1080}, device_scale_factor=1.0 ) # Initialize the model llm = ChatOpenAI( model="gpt-4.1", ) # Create and run the agent with job extraction task agent = Agent( task="""1. Go to https://www.onkernel.com/docs 2. Navigate to the main Jobs page 3. Extract all the job posting URLs. List each URL you find.""", llm=llm, browser_session=browser ) result = await agent.run() print(f"Job URLs found:\n{result.final_result()}") # Flush traces to Laminar Laminar.flush() # Delete the browser for those who left open the live view url client.browsers.delete_by_id(kernel_browser.session_id) asyncio.run(main()) ``` -------------------------------- ### Install MCP for VS Code Source: https://github.com/kernel/docs/blob/main/reference/cli/mcp.mdx Installs the Kernel MCP server configuration for Visual Studio Code. This command automatically configures the MCP server in VS Code's settings file. ```bash kernel mcp install --target vscode ``` -------------------------------- ### Start Login Session (Python) Source: https://github.com/kernel/docs/blob/main/auth/react.mdx Initiate a login session on your backend using Kernel's auth API. This returns a connection ID and a handoff code required by the frontend component. ```python auth = await kernel.auth.connections.create( domain="netflix.com", profile_name="user-123", ) login = await kernel.auth.connections.login(auth.id) # login.id, login.handoff_code ``` -------------------------------- ### Start and Stop Recordings Source: https://github.com/kernel/docs/blob/main/browsers/replays.mdx Initiate and terminate video recordings of browser sessions. You can start a replay recording using the session ID and stop it using the replay ID, optionally specifying the session ID again. ```APIDOC ## Start Recording ### Description Starts a new replay recording for a given browser session. ### Method `kernel.browsers.replays.start(sessionId)` ### Parameters #### Path Parameters - **sessionId** (string) - Required - The ID of the browser session to record. ### Response #### Success Response (200) - **replay_id** (string) - The unique identifier for the started replay recording. ## Stop Recording ### Description Stops an ongoing replay recording and initiates processing. ### Method `kernel.browsers.replays.stop(replayId, { id: sessionId })` ### Parameters #### Path Parameters - **replayId** (string) - Required - The ID of the replay recording to stop. - **id** (string) - Required - The ID of the browser session associated with the replay. ### Request Body (Not applicable for this operation, parameters are passed directly) ### Response (No specific response details provided in the source, typically indicates success or processing status.) ``` -------------------------------- ### Trigger Re-authentication Manually Source: https://github.com/kernel/docs/blob/main/auth/connection-lifecycle.mdx Call `.login()` on any connection to trigger authentication immediately, without waiting for the next scheduled health check. If the profile is already logged in, it returns quickly without starting a new flow. If the connection needs auth, it starts a new login session. ```APIDOC ## Trigger Re-authentication Manually ### Description Manually triggers the authentication process for a connection. ### Method `kernel.auth.connections.login(auth.id)` ### Parameters #### Path Parameters - **auth.id** (string) - Required - The ID of the connection to authenticate. ``` ```APIDOC ## Trigger Re-authentication Manually ### Description Manually triggers the authentication process for a connection. ### Method `kernel.auth.connections.login(auth.id)` ### Parameters #### Path Parameters - **auth.id** (string) - Required - The ID of the connection to authenticate. ``` -------------------------------- ### Create Computer Use App with Kernel CLI Source: https://github.com/kernel/docs/blob/main/integrations/computer-use/openai.mdx Use the Kernel CLI to quickly set up a new application pre-configured with the Computer Use integration. Choose between TypeScript or Python for your project. ```bash kernel create --name my-computer-use-app --template cua ``` -------------------------------- ### Get a project by ID Source: https://github.com/kernel/docs/blob/main/info/projects.mdx Retrieves a specific project by its unique identifier. ```APIDOC ## GET /projects/{id} ### Description Get a project by ID. ### Method GET ### Endpoint /projects/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the project. ### Response #### Success Response (200) - **id** (string) - The unique identifier of the project. - **name** (string) - The name of the project. - **status** (string) - The status of the project (e.g., 'active', 'archived'). ### Response Example ```json { "id": "proj_abc123", "name": "staging", "status": "active" } ``` ``` -------------------------------- ### Deploy App with Environment Variables Source: https://github.com/kernel/docs/blob/main/apps/secrets.mdx Use the `kernel deploy` command with `--env` flags for individual variables or `--env-file` to load from a .env file. Both can be combined. ```bash # Using --env flag for individual variables kernel deploy my_app.ts --env OPENAI_API_KEY=sk-... --env ANTHROPIC_API_KEY=sk-ant-... # Using --env-file to load from a file kernel deploy my_app.ts --env-file .env # Combine both approaches kernel deploy my_app.ts --env-file .env --env OPENAI_API_KEY=sk-... ```