Skip to main content

Browser Agent

The meshbrow-agent is a daemon that runs alongside each browser session inside its network namespace or Firecracker VM. It provides health monitoring, process supervision, metrics collection, and filesystem watching.
The agent is automatically deployed by the Meshbrow platform. You only need to install it manually for self-hosted or custom setups.

Installation

brew tap meshbrow-dev/tap
brew install meshbrow-agent
Verify the installation:
meshbrow-agent --version
# meshbrow-agent v0.1.0

Usage

meshbrow-agent \
  --session-id sess_abc123 \
  --socket /run/meshbrow/agent.sock \
  --workspace /tmp/meshbrow-session \
  --log-level info

Configuration

FlagEnv VariableDefaultDescription
--session-idMESHBROW_SESSION_ID(required)Browser session ID
--socketMESHBROW_SOCKET/run/meshbrow/agent.sockUnix socket path
--workspaceMESHBROW_WORKSPACE/tmp/meshbrow-sessionSession workspace directory
--log-levelMESHBROW_LOG_LEVELinfoLog level (debug, info, warn, error)
--heartbeat-interval5sHeartbeat reporting interval
--metrics-interval10sMetrics collection interval

What It Does

The agent provides five core capabilities:

Health Reporting

Sends periodic heartbeats to the host (browserd) over the unix socket. Reports:
  • Browser process alive/dead status
  • CPU and memory usage
  • Uptime
  • Process ID

Browser Process Supervision

Monitors the Chromium process. If the browser crashes, the agent reports it immediately via a health status change, allowing browserd to restart or destroy the session.

Metrics Collection

Collects system metrics at configurable intervals:
  • CPU utilization
  • Memory usage (used/total)
  • Disk usage
  • Network I/O (bytes sent/received)
  • Open file descriptors
  • Active goroutines

Filesystem Watching

Monitors the session workspace for changes and streams events:
  • File creation
  • File modification
  • File deletion
Excludes noise directories (.git, node_modules, __pycache__).

Graceful Shutdown

Handles SIGTERM and SIGINT signals. On shutdown:
  1. Stops all subsystems (heartbeat, metrics, watcher)
  2. Sends a deregistration message to the host
  3. Exits cleanly

Architecture

┌──────────────────────────────────────────────────┐
│ Network Namespace / Firecracker VM               │
│                                                  │
│  ┌──────────────────────────────────────┐       │
│  │         meshbrow-agent                │       │
│  │                                       │       │
│  │  ┌───────────┐  ┌────────────────┐  │       │
│  │  │ FS Watcher │  │ Health/HB      │  │       │
│  │  └───────────┘  └────────────────┘  │       │
│  │  ┌───────────┐  ┌────────────────┐  │       │
│  │  │ Metrics   │  │ Command Rx     │  │       │
│  │  └───────────┘  └────────────────┘  │       │
│  └──────────────────────────────────────┘       │
│           │ unix socket                          │
│           │                                      │
│  ┌────────┴─────────────────────────────┐       │
│  │         chromium (headless)            │       │
│  └───────────────────────────────────────┘       │
└──────────┼───────────────────────────────────────┘

   ┌───────┴───────┐
   │ Meshbrow Host │
   │   (browserd)  │
   └───────────────┘

Protocol Messages

The agent communicates via newline-delimited JSON over the unix socket.

Agent → Host

TypeDescription
registerInitial registration with version, workspace, PID
heartbeatPeriodic health status
metricsSystem metrics snapshot
fs_eventFilesystem change event
deregisterGraceful shutdown notification
health_responseResponse to on-demand health check
metrics_responseResponse to on-demand metrics request

Host → Agent

TypeDescription
shutdownInitiate graceful shutdown
health_checkRequest immediate health status
collect_metricsRequest immediate metrics snapshot

Building from Source

git clone https://github.com/meshbrow-dev/meshbrow-agent.git
cd meshbrow-agent

# Native build
go build -o meshbrow-agent ./cmd/agent

# Static Linux binary (for containers/VMs)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o meshbrow-agent ./cmd/agent

Development

go test ./...
go test -race ./...
golangci-lint run