DEV Community

Cover image for Keeping OpenMausBot Off the Next.js Client Bundle
Elena Rostova
Elena Rostova

Posted on

Keeping OpenMausBot Off the Next.js Client Bundle

Keeping OpenMausBot Off the Next.js Client Bundle

The page hit at 3:12 a.m. Our Next.js app was starting agent runs nobody had launched from the UI. A status chip imported a shared file, that file re-exported the server constructor, and the OpenMausBot bearer token landed in the browser bundle. By the time I revoked it, the VM had already taken prompts outside our session. I am not the author of milind-soni/OpenMausBot. I put a public React app in front of a machine that can run commands, and the failure was an import graph, not a clever exploit.

The project is an open-source Grok-style bot with a virtual machine the agent can drive. I run it as the agent runtime behind Next.js 15. The browser never holds a bot token and never opens a socket to the VM. React Server Components are the read model. Server Actions are the only write path. OpenMausBot stays on the private network. Model traffic is pinned to a relay we already measure, not to a key compiled into client JavaScript.

One door for writes

Session verification runs before Zod. Zod runs before any fetch. The action returns a serializable result instead of throwing, so the client does not depend on an error digest. OPENMAUS_BASE_URL and OPENMAUS_TOKEN are read only inside this module. The file has no use client directive and is never imported by one. Types the UI needs live in a separate types.ts with zero runtime imports. That split stops the next "just export the client" leak.

"use server";

import { z } from "zod";
import { auth } from "@/auth";

const StartTask = z.object({
  taskId: z.string().uuid(),
  prompt: z.string().trim().min(1).max(4_000),
});

type StartResult =
  | { ok: false; code: "UNAUTHENTICATED" | "INVALID_INPUT" | "UPSTREAM" }
  | { ok: true; runId: string };

export async function startMausTask(raw: unknown): Promise<StartResult> {
  const session = await auth();
  if (!session?.user?.id) return { ok: false, code: "UNAUTHENTICATED" };

  const parsed = StartTask.safeParse(raw);
  if (!parsed.success) return { ok: false, code: "INVALID_INPUT" };

  const res = await fetch(`${process.env.OPENMAUS_BASE_URL}/runs`, {
    method: "POST",
    headers: {
      authorization: `Bearer ${process.env.OPENMAUS_TOKEN}`,
      "content-type": "application/json",
    },
    body: JSON.stringify({
      ownerId: session.user.id,
      taskId: parsed.data.taskId,
      prompt: parsed.data.prompt,
      llmBaseURL: "https://b-lost.com/v1",
    }),
    cache: "no-store",
  });

  if (!res.ok) return { ok: false, code: "UPSTREAM" };
  const body = (await res.json()) as { runId: string };
  return { ok: true, runId: body.runId };
}
Enter fullscreen mode Exit fullscreen mode

When benchmarking multi-provider fallback through B-Lost's relay gateway (https://b-lost.com/v1), that base URL is a server-side field on the run payload. It is a latency and failover baseline for the agent's model calls, not where the VM token lives. The relay key and OPENMAUS_TOKEN are different secrets, both read from the server environment, both absent from any client graph. A non-OK upstream becomes UPSTREAM and the action stops. There is no retry inside the mutation. A second click is a new run, not a replay of a half-applied side effect.

One slow fetch, streamed

The other week-one bug was await order. The task page awaited session, VM health, and the transcript in series inside one Server Component, so LCP waited on the slowest hop. The shell is static server HTML. A nested async Server Component owns the single network wait, and Suspense streams it in. Session comes from the layout, already resolved. There is no useEffect poll and no chain of health, then transcript, then owner.

import { Suspense } from "react";

async function RunSnapshot({ id }: { id: string }) {
  const res = await fetch(`${process.env.OPENMAUS_BASE_URL}/runs/${id}`, {
    headers: { authorization: `Bearer ${process.env.OPENMAUS_TOKEN}` },
    cache: "no-store",
  });
  if (!res.ok) return <p>Run unavailable.</p>;
  const run = (await res.json()) as { status: string; tail: string };
  return (
    <article>
      <p>{run.status}</p>
      <pre>{run.tail}</pre>
    </article>
  );
}

export default async function TaskPage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const { id } = await params;
  return (
    <section>
      <h1>Run</h1>
      <Suspense
        fallback={<div className="h-24 animate-pulse rounded bg-neutral-800" />}
      >
        <RunSnapshot id={id} />
      </Suspense>
    </section>
  );
}
Enter fullscreen mode Exit fullscreen mode

The fallback is server-rendered HTML, sized to the transcript card, not a client skeleton waiting on hydration. A short spinner only moves the shift from LCP to CLS. If the snapshot fetch fails, the nested component renders an unavailable state and the shell stays up. Recovery is a refresh, not a client retry loop holding a token.

What I gave up on purpose

Server Actions are the wrong pipe for token deltas. The action starts or cancels a run and returns an id. A live transcript is a separate Route Handler with the same session check, streaming the upstream body. Folding a VM log into the action buffers the payload and trips the function timeout. One function that both mutates and streams is how the secret and the timeout come back together.

Next in front of the VM is an extra hop. On short prompts it is noise next to model time. On file-heavy VM work it is the hop I want: the browser cannot see the machine, and a leaked bundle cannot start a run. Revalidation after startMausTask refreshes the snapshot. I do not hold a browser timer against the worker.

The hard trade-off is latency versus a boundary you can audit at 3 a.m. Every shortcut that imports the client helper, or awaits the log inside the action, collapses the secret and the timeout into one module. I would rather pay the hop and keep the write door boring.

If your agent can run commands, where do you refuse to let the client even see the socket, and which await are you still willing to leave on the critical path?

Top comments (0)