Skip to content
pols.so docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

TypeScript client

Use pols from Node.js with the typed TypeScript client, generated from the same OpenAPI spec as the API.

@peweo/pols is a typed client for the pols API. Its types are generated from the API’s OpenAPI spec, so they match the API exactly; on top of them it adds helpers for waiting, streaming and computer use.

Install

The client is not published on a package registry yet; publishing it is coming soon. Until then it is built from its source in the pols.so repository (clients/typescript) and installed as a package file. To get it, write to team@peweo.com. With the package file, install it into your project:

npm install ./peweo-pols-0.1.0.tgz

It needs Node.js 20 or newer.

Create, run, clean up

import { createPolsClient } from "@peweo/pols";

const pols = createPolsClient({ apiKey: process.env.POLS_API_KEY! });

let sb = await pols.sandboxes.create({
  name: "ci-run",
  size: "large",
  env: { NODE_ENV: "test" },
  secrets: ["GITHUB_TOKEN"], // vault entries, set as environment variables
});
sb = await pols.sandboxes.waitFor(sb); // until it runs

for await (const ev of pols.execStream(sb.id, { command: ["bash", "-lc", "npm test"] })) {
  if (ev.type === "stdout") process.stdout.write(ev.data ?? "");
  if (ev.type === "stderr") process.stderr.write(ev.data ?? "");
  if (ev.type === "exit") console.log("exit code", ev.exit_code);
}

await pols.files.write(sb.id, "/home/user/notes.md", "# notes");
const bytes = await pols.files.read(sb.id, "/home/user/notes.md");

await pols.sandboxes.waitFor(await pols.sandboxes.stop(sb.id));

Lifecycle calls return as soon as the API accepted them; waitFor polls until the sandbox reached its desired state.

What the client covers

Area Calls
Sandboxes pols.sandboxes.list, .get, .create, .fork, .rename, .resize, .setEgress, .rollback, .stop, .resume, .delete, .stats, .events, .eventThumbnail, .setTimelineCapture, .waitFor
Checkpoints pols.checkpoints.list, .create, .delete
Commands pols.exec (collected output), pols.execStream (streamed events)
Detached processes pols.processes.start, .list, .output, .signal
Files pols.files.read, .write, .list, .watch, .track, .changes, .untrack
Sandbox users pols.users.list, .add, .remove
Templates pols.templates.list, .get, .create (from a sandbox, an image or a Dockerfile), .delete
Databases pols.databases.list, .get, .create, .delete, .link, .unlink, .backups, .rotate
Vault pols.vault.list
Org pols.org, pols.orgs, pols.orgStats, pols.usage, pols.balance, pols.apiKeys.list, pols.webhooks.list, .deliveries
Billing pols.billing.get, .put, .topUp, .topUps, .getTopUp, .autoTopUp, .setAutoTopUp, .invoices, .getInvoice
Computer use pols.computer.screenshot, .click, .doubleClick, .drag, .type, .key, .scroll, .action, .control; pols.browser.cdp
Sites pols.sites.list, .get, .create, .update, .delete, .publish, .versions, .restore, .rotateLink, .redirects, .setRedirects, .domains
Access pols.ports.list, .publish, .unpublish, .link, .domains; pols.desktop.link; pols.sshKeys.list, .create, .delete; pols.ssh

pols.sandboxes.create, .fork and pols.templates.create take an options object after the request with an idempotencyKey: calling again with the same key and input within 24 hours returns what the first call made instead of making another, so a create is safe to retry after a timeout or a lost answer. To act as a sandbox user instead of the default user, set user in the request of pols.exec, pols.execStream and pols.processes.start, or pass { user } to pols.files.write, .list, .watch, .track, .changes and .untrack, the pols.computer calls, pols.browser.cdp, pols.desktop.link and pols.ssh.

For anything without a helper, pols.raw is the typed openapi-fetch client for every endpoint.

createPolsClient takes the apiKey, and optionally a baseUrl (default https://api.pols.so) and a custom fetch. It refuses a plain http:// base URL other than localhost unless you set allowInsecureHttp. waitFor gives up after 5 minutes unless you pass timeoutMs, and throws when the sandbox ends in error.

Errors

Failed calls throw a PolsError with the HTTP status and the API’s stable error code, such as quota_exceeded or not_found. See Errors for what each code means.

Computer use and the browser

import { chromium } from "playwright";

const png = await pols.computer.screenshot(sb.id); // Uint8Array, a PNG
await pols.computer.click(sb.id, 960, 540);
await pols.computer.type(sb.id, "hello");

const { websocket_url } = await pols.browser.cdp(sb.id); // connect within 5 minutes
const browser = await chromium.connectOverCDP(websocket_url);

See Computer use.