Skip to main content
In addition to our browser API, Kernel provides a code execution platform for deploying and invoking code. Typically, Kernel’s code execution platform is used for deploying and invoking browser automations or web agents. When using Kernel’s code execution platform, we co-locate your code with any Kernel browser environments you instantiate in your app. This solves common issues with browser connections over CDP:
  • Reduced latency: Your code runs directly alongside the browser, reducing round-trip latency
  • Improved reliability: Fewer unexpected disconnects between your code and browser
  • Higher throughput: Eliminates bandwidth bottlenecks during data-intensive operations like screenshots
Install our MCP server to give your coding agent our search_docs tool.

Apps, Actions, and Invocations

An App is a codebase deployed on Kernel. You can deploy any codebase in Typescript or Python on Kernel. An Action is an invokable method within an app. Actions allow your to register entry points or functions that can be triggered on-demand. Actions can call non-action methods. Apps can have multiple actions. An Invocation is a single execution of an action. Invocations can be triggered via API, scheduled as a job, or run on-demand.

Getting started: create an app

First, install the Kernel SDK for your language:
npm install @onkernel/sdk
Then create an app:
import Kernel, { type KernelContext } from '@onkernel/sdk';

const kernel = new Kernel();
const app = kernel.app('my-app-name');
Then, define and register an action that you want to invoke.

Registering actions

Action methods receive two parameters:
  • runtimeContext: Contextual information provided by Kernel during execution
  • payload: Optional runtime data that you provide when invoking the action (max 64 KB). Read more
You can register actions using either approach:
app.action('my-action-name', async (ctx: KernelContext, payload) => {
  const { tshirt_size, color, shipping_address } = payload;
  // Your action logic here
  return { order_id: 'example-order-id' };
});

Define then register

This approach is better for larger apps, unit testing, and team collaboration since functions can be tested independently and reused across multiple actions.
const myActionMethod = async (ctx: KernelContext, payload) => {
  const { tshirt_size, color, shipping_address } = payload;
  // Your action logic here
  return { order_id: 'example-order-id' };
};

app.action('my-action-name', myActionMethod);

Environment variables

You can set environment variables when deploying your app. They then can be accessed in the usual way:
const ENV_VAR = process.env.ENV_VAR;
const myActionMethod = async (runtimeContext, payload) => {
  // ...
};

Return values

Action methods can return values, which will be included in the invocation’s final response.
const myActionMethod = async (runtimeContext, payload) => {
  const { tshirt_size, color, shipping_address } = payload;
  // ...
  return {
    order_id: "example-order-id",
  }
};
The examples above show actions returning data.

Building browser automations with Kernel apps

To implement a browser automation or web agent, instantiate an app and define an action that creates a Kernel browser.
Kernel browsers launch with a default context and page. Make sure to access the existing context and page (contexts()[0] and pages()[0]), rather than trying to create a new one.
import Kernel, { type KernelContext } from '@onkernel/sdk';
import { chromium } from 'playwright';

const kernel = new Kernel();
const app = kernel.app('browser-automation');

app.action('get-page-title', async (ctx: KernelContext, payload) => {
  const kernelBrowser = await kernel.browsers.create({
    invocation_id: ctx.invocation_id,
  });

  const browser = await chromium.connectOverCDP(kernelBrowser.cdp_ws_url);
  const context = browser.contexts()[0] || (await browser.newContext());
  const page = context.pages()[0] || (await context.newPage());

  try {
    await page.goto('https://www.google.com');
    const title = await page.title();
    return { title };
  } finally {
    await browser.close();
  }
});
Web agent frameworks sometimes require environment variables (e.g. LLM API keys). Set them when deploying your app.

Next steps

Once you’re happy with your app, follow these steps to deploy and invoke it on the Kernel platform.