Workers

Serverless runtime for apps and agents

Run APIs, webhooks, full-stack frameworks, and agent code on an isolate-based serverless runtime that starts in milliseconds and scales to zero between requests. Write standard fetch handlers, or use Ploy Start for typed routes, and attach databases, queues, and storage with a line of ploy.yaml.

Worker Code Example

Requests Today

1,284,392

+12% from yesterday

Avg Latency

12ms

P95: 45ms

Error Rate

0.02%

3 errors today

Worker Code

Example API worker running at the edge

api/hello.ts
// api/hello.ts
export default {
  async fetch(request, env) {
    const url = new URL(request.url);

    if (url.pathname === "/api/users") {
      const users = await env.DB.prepare(
        "SELECT id, name, email FROM users LIMIT 10"
      ).all();

      return Response.json({ users: users.results });
    }

    return Response.json({
      message: "Hello from the edge!",
      timestamp: new Date().toISOString()
    });
  }
}

Key Features

Millisecond Cold Starts

V8 isolates start in milliseconds, so there is no warm pool to manage and nothing running when traffic is zero.

Standard Web APIs

fetch, Request, Response, and ctx.waitUntil() for background work after the response is sent.

Frameworks Included

Deploy Next.js, Vite, and TanStack Start apps, or a bare worker, from the same ploy.yaml.

Bindings, Not Clients

Databases, queues, state, files, and sandboxes arrive on env, typed by ploy types, with no connection strings.

Worker Example

A worker is a module with a fetch handler. Bindings declared in ploy.yaml show up on env.

src/index.ts
export default {
  async fetch(request, env) {
    const url = new URL(request.url);

    if (url.pathname === "/api/users") {
      const { results } = await env.DB
        .prepare("SELECT id, name FROM users")
        .all();
      return Response.json({ users: results });
    }

    return new Response("Not Found", { status: 404 });
  },
} satisfies Ploy;

Ready to get started?

Deploy your first project in minutes with Ploy.