Give an AI SDK agent devices
Let an agent you build with the Vercel AI SDK drive Limrun iOS simulators and Android emulators.
An agent built with the Vercel AI SDK can drive Limrun devices in two ways:
@limrun/ai-sdk: your code creates a device, hands the model tools bound to that one device, and deletes it when the run ends. Use it when your program decides which devices exist, such as a test runner or a backend job.- The remote MCP server: the model creates, drives, and deletes devices itself, including macOS virtual machines. Use it when the agent should own the whole loop.
Before you start
-
Node.js 22 or newer, which AI SDK 7 requires.
-
A Limrun API key. Create one at console.limrun.com/settings under API Keys, and export it where your code runs:
export LIM_API_KEY=<your-api-key> -
Credentials for the model you call. The examples use a model string, which the AI SDK sends through the Vercel AI Gateway.
Drive a device your code creates
Install the package with its peer dependencies:
npm install @limrun/ai-sdk @limrun/api ai zod
This script creates a simulator, lets the model read a web page on it, and deletes the simulator:
import { generateText, stepCountIs } from 'ai';
import Limrun, { Ios } from '@limrun/api';
import { iosTools } from '@limrun/ai-sdk';
const lim = new Limrun();
const instance = await lim.iosInstances.create({ wait: true });
const client = await Ios.createInstanceClient({
apiUrl: instance.status.apiUrl!,
token: instance.status.token!,
});
try {
const { text } = await generateText({
model: 'anthropic/claude-sonnet-5.5',
tools: iosTools(client),
stopWhen: stepCountIs(20),
prompt: 'Open https://lim.run in Safari and tell me what the page heading says.',
});
console.log(text);
} finally {
client.disconnect();
await lim.iosInstances.delete(instance.metadata.id);
}
iosTools(client) binds every tool to that client. The client holds only the instance’s own URL and token, so the model can act on this simulator and nothing else: it never sees an instance ID or your API key. stopWhen lets the model call tools for up to 20 steps; without it, generateText stops after the first tool call. The finally block deletes the simulator even when the run fails, so it does not keep running and billing.
For Android, create the instance with lim.androidInstances.create, connect with createInstanceClient from @limrun/api, and pass that client to androidTools.
To test your own app, install it from your code before the run, for example with client.installApp(url) on iOS, and name it in the prompt.
Tools
The tool names and inputs follow the methods of the @limrun/api instance clients. iosTools(client) returns:
| Tool | What it does |
|---|---|
screenshot |
Returns a screenshot and the accessibility tree. |
performActions |
Runs a batch of actions in order, with the same action shape as client.performActions: taps, element actions, typing, keys, scrolling, waits, buttons, and raw touches. The batch stops at the first action that fails. |
openUrl |
Opens a URL in Safari, or a deeplink in its app. |
listApps, launchApp, terminateApp |
Lists, launches, or stops apps by bundle ID. |
appLogTail |
Reads an app’s last log lines. |
androidTools(client) returns:
| Tool | What it does |
|---|---|
screenshot |
Returns a screenshot and the UIAutomator XML. |
tap, setText |
Taps, or types text, at an element selector or a point. setText without a target types into the focused field. |
pressKey |
Presses a key such as BACK or ENTER. |
scrollScreen, scrollElement |
Scrolls the screen, or a container matched by selector or point. |
findElement |
Finds the elements that match a selector. |
openUrl |
Opens a URL or deeplink. |
listApps, launchApp, terminateApp |
Lists, launches, or stops apps by package name. |
The screenshot tools send the image to the model as an image and the tree as text. Each factory returns a plain object, so you can pass a subset of the tools. The tools reuse the client’s connection for every call and leave it open; your code disconnects it.
When a tool fails, the AI SDK hands the error message to the model instead of stopping the run. A selector that matches nothing, for example, comes back with a message that tells the model to fix the selector or wait for the element.
Let the model create devices
The AI SDK has an MCP client, so an agent can use the remote MCP server directly. The server’s tools create, list, drive, and delete iOS simulators, Android emulators, and macOS virtual machines in your organization. Install the client package:
npm install @ai-sdk/mcp ai zod
Connect with your API key and pass the server’s tools to generateText:
import { generateText, stepCountIs } from 'ai';
import { createMCPClient, splitMCPAppTools } from '@ai-sdk/mcp';
const mcp = await createMCPClient({
transport: {
type: 'http',
url: 'https://mcp.limrun.com/mcp',
headers: { Authorization: `Bearer ${process.env.LIM_API_KEY}` },
},
});
try {
const { modelVisible } = splitMCPAppTools(await mcp.listTools());
const { text } = await generateText({
model: 'anthropic/claude-sonnet-5.5',
tools: mcp.toolsFromDefinitions(modelVisible),
stopWhen: stepCountIs(20),
prompt:
'Create an Android emulator, open https://lim.run, ' +
'tell me what the page heading says, then delete the emulator.',
});
console.log(text);
} finally {
await mcp.close();
}
splitMCPAppTools drops the device panel tools, which MCP hosts show only to the user, not to the model. mcp.tools() would return them too.
These tools act with your API key on every instance in the organization, and devices the model forgets to delete keep running until their inactivity timeout. The remote MCP server page lists the tools.