# Actor Runtime Socket

> Source: `src/content/docs/actors/actor-runtime-socket.mdx`
> Canonical URL: https://rivet.dev/docs/actors/actor-runtime-socket
> Description: Access an actor's SQLite database from another local process.

---
The Actor Runtime Socket is an advanced Beta API for integrating Rivet Actors with external software without sacrificing performance. It currently exposes SQLite over Unix domain sockets in the native runtime.

For example, an agentOS agent can use the socket to work with its actor's SQLite database. Software orchestrated by an actor, such as another process or container, can use it to access the actor's runtime resources. Like the Chrome DevTools Protocol exposes a browser to external tools, the Actor Runtime Socket exposes selected actor capabilities to colocated software.

## Quickstart

Enable the socket, call `c.actorRuntimeSocket()` to get its path, and pass that path to your process:

```ts actor.ts
import { spawn } from "node:child_process";
import { actor } from "rivetkit";
import { db } from "rivetkit/db";

export const example = actor({
  options: { enableActorRuntimeSocket: true },
  db: db({
    onMigrate: (db) =>
      db.execute("CREATE TABLE IF NOT EXISTS items (value TEXT)"),
  }),
  actions: {
    startWorker: async (c) => {
      // Get the Unix socket path external processes use
      // to communicate with the actor.
      // (Example: /tmp/rivet-actor-runtime.abc/def.sock)
      const { path } = await c.actorRuntimeSocket();

      // Spawn a process that can access the actor's
      // SQLite database over the socket.
      spawn(process.execPath, ["worker.js"], {
        env: { ...process.env, ACTOR_RUNTIME_SOCKET_PATH: path },
      });
    },
  },
});
```

```ts worker.ts
import { connectRuntimeSocket } from "./generated/runtime-socket-client";

const db = await connectRuntimeSocket(process.env.ACTOR_RUNTIME_SOCKET_PATH!);
const rows = await db.query("SELECT value FROM items", []);
console.log(rows);
```

The path is valid only for the current actor generation, so get it again after the actor restarts or wakes. Only share it with trusted local processes.

## Protocol

The [protocol schema](https://github.com/rivet-dev/rivet/blob/main/engine/sdks/rust/actor-runtime-socket-protocol/schemas/v1.bare) defines the handshake, SQLite requests, values, responses, and errors. Generate codecs using vbare's [TypeScript](https://github.com/rivet-dev/vbare/tree/main/typescript) or [Rust](https://github.com/rivet-dev/vbare/tree/main/rust) tooling, then add a small Unix socket wrapper for its length-prefixed frames. `connectRuntimeSocket` above represents that application-specific wrapper.

## SQLite transaction interleaving

Separate socket requests can interleave with SQLite work from the main actor. For multi-request atomic work, begin a transaction with a client-generated `leaseKey`, include that key with each query, and commit or roll back with the same key. Other actor and socket SQL waits until that transaction finishes.

_Source doc path: /docs/actors/actor-runtime-socket_
