Freestyle Docs

Freestyle / Guides

Run GPU workloads in a sandbox

Start a GPU-accelerated Chromium browser for Playwright, or run your own graphics workload on a GPU-enabled Ubuntu VM.

For browser automation, start from freestyle/chromium-v1-gpu. This public snapshot opens with GPU-accelerated Chromium already running. For your own EGL or OpenGL application, start from freestyle/ubuntu-gpu. GPUs and the Display API are in beta and available by request. Request beta access for your team.

Automate a GPU-accelerated Chromium browser

Install the SDK and Playwright on your machine. Set FREESTYLE_API_KEY in your environment.

npm install freestyle playwright-core

Create the VM from your backend. The firewall rule lets Chromium visit public websites.

import { Freestyle } from "freestyle";

const freestyle = new Freestyle({ apiKey: process.env.FREESTYLE_API_KEY });
const { vmId } = await freestyle.vms.create({
  snapshotId: "freestyle/chromium-v1-gpu",
  experimentalGpu: true,
  firewall: { rules: [{ action: "allow", source: {}, destination: { public: true } }] },
});
console.log(vmId);

In a terminal, substitute the printed VM ID and leave this command running. It forwards Chromium’s private DevTools port to your machine.

npx freestyle vm port-forward <vm-id> 9222

Connect Playwright to the running browser and take a screenshot.

import { chromium } from "playwright-core";

const browser = await chromium.connectOverCDP("http://127.0.0.1:9222");
try {
  const page = browser.contexts()[0].pages()[0];
  await page.goto("https://example.com");
  await page.screenshot({ path: "example.png" });
} finally {
  await browser.close();
}

To watch the live tab and take over with your mouse or keyboard, follow Watch and control Chromium in a sandbox.

When you’re finished, stop the port forward with Ctrl+C and delete the VM with await freestyle.vms.ref(vmId).delete().

Run your own GPU application

Use the GPU Ubuntu base for a renderer or other graphics application. This example needs only the SDK and runs entirely inside the VM.

const { vm } = await freestyle.vms.create({
  snapshotId: "freestyle/ubuntu-gpu",
  experimentalGpu: true,
  firewall: { rules: [] },
});
try {
  const result = await vm.exec("ls /dev/dri/renderD*");
  console.log(result.stdout); // e.g. /dev/dri/renderD128
  // Run your EGL or OpenGL application here.
} finally {
  await vm.delete();
}

GPU access is selected per VM. CPU-only workloads can still run on the same hosts.

esc