01Install
Install from npm into your project. Add puppeteer-core or playwright if you use a browser backend.
BASH
npm install @lov3kaizen/agentsea-surf02Example
TS
import { SurfAgent, createNativeBackend } from '@lov3kaizen/agentsea-surf';
const backend = createNativeBackend();
await backend.connect();
const agent = new SurfAgent('session-1', backend, {
maxSteps: 20,
vision: { model: 'claude-sonnet-4-6', maxTokens: 4096, includeScreenshotInResponse: true },
});
const result = await agent.execute('Open Chrome and navigate to google.com');
console.log('Result:', result.response);
await backend.disconnect();03Key API
new SurfAgent(sessionId, backend, config?)Methods: execute(task, context?), executeStream(task, context?), stop(), getState().
createNativeBackend(options?)Backend for the local desktop. Supports macOS, Linux and Windows.
PuppeteerBackend and DockerBackendBrowser backend (headless, viewport, initialUrl) and Docker desktop backend (image, resolution, removeOnDisconnect).
createSurfTools(backend)Returns the 8 computer-use tools for direct use: screenshot, click, typeText, scroll, drag, keyPress, cursorMove, wait.
SurfModule.forRoot({ backend, config, enableRestApi, enableWebSocket })NestJS module, imported from '@lov3kaizen/agentsea-surf/nestjs'. backend is a config such as { type: 'native' }.
04Caveats
- Browser backends need puppeteer-core or playwright. sharp is a regular dependency.
- The example needs a vision-capable Claude model such as claude-sonnet-4-6. How the API key is supplied is not described.
- A desktop agent needs OS permissions to capture the screen and send input. These are not listed.
- The Docker backend uses the image agentsea/desktop:ubuntu-22.04. Build and pull steps are not described. Do not rely on the sandbox options as a complete security control.
05Streaming execution
executeStream yields an event for each screenshot, each action and the final result. Use it to show progress while a task runs.
TS
for await (const event of agent.executeStream('Search for weather')) {
switch (event.type) {
case 'screenshot':
console.log('Screenshot taken');
break;
case 'action':
console.log(`Executing: ${event.action.description}`);
break;
case 'complete':
console.log('Task completed:', event.response);
break;
}
}06Sandbox
The sandbox option limits what the agent may do. Each limit is optional.
TS
const agent = new SurfAgent('session', backend, {
sandbox: {
enabled: true,
maxActionsPerMinute: 60,
blockedDomains: ['malicious-site.com'],
blockedCommands: ['rm -rf', 'sudo'],
blockedPaths: ['/etc', '/root'],
},
});- These are guardrails, not a full security boundary. Run the agent in an isolated machine or container.
07NestJS endpoints
With enableRestApi and enableWebSocket set, SurfModule exposes these routes under /surf. The routes are listed from the controller and gateway source.
- REST: POST /surf/execute, POST /surf/action, POST /surf/screenshot, GET /surf/screen, GET /surf/sessions, GET /surf/sessions/:sessionId, POST /surf/sessions/:sessionId/stop, GET /surf/status.
- WebSocket events: execute (emits stream, complete, error), action, screenshot, stop, getState and status.