Skip to main content

Crate clawbox_server

Crate clawbox_server 

Source
Expand description

§clawbox-server

HTTP API server for the clawbox sandboxed agent execution service.

§Overview

clawbox-server is the Axum-based HTTP server that ties all clawbox components together. It exposes REST endpoints for tool execution, container management, agent orchestration, health checking, and Prometheus metrics. The server manages shared application state including the WASM sandbox engine, container manager, credential store, output scanner, and audit log.

§Usage

use clawbox_server::{ClawboxConfig, AppState, build_router};
use std::sync::Arc;

let config = ClawboxConfig::load("config/clawbox.toml")?;
let state = Arc::new(AppState::new(config).await?);
let app = build_router(state);

let listener = tokio::net::TcpListener::bind("127.0.0.1:9800").await?;
axum::serve(listener, app).await?;

§API Routes

MethodPathAuthDescription
GET/healthPublicHealth check with component status
GET/metricsPublicPrometheus metrics endpoint
POST/executeBearerExecute a tool in WASM sandbox
GET/toolsBearerList registered tool manifests
POST/tools/registerBearerRegister a tool manifest
POST/tools/reloadBearerHot-reload WASM tools from disk
GET/containersBearerList active containers
POST/containers/spawnBearerSpawn a new container
GET/containers/{id}BearerGet container details
DELETE/containers/{id}BearerKill and remove a container
POST/agentsBearerRegister a new agent
GET/agentsBearerList registered agents
GET/agents/{id}BearerGet agent details
POST/agents/{id}/startBearerStart an agent’s container
POST/agents/{id}/stopBearerStop an agent’s container
DELETE/agents/{id}BearerRemove an agent

§Features

  • Axum HTTP framework — Async, tower-based middleware stack
  • Bearer token auth — Constant-time token comparison via subtle::ConstantTimeEq
  • Concurrency limiting — Tower ConcurrencyLimitLayer on protected routes (max 10)
  • Request size limiting — 10 MB body limit on protected endpoints
  • Prometheus metrics — Request counts, durations, container gauges, execution histograms
  • Graceful shutdown — SIGTERM/Ctrl+C handling with container cleanup
  • TOML configuration — Layered config for server, sandbox, proxy, credentials, containers, and logging

§Architecture

ModulePurpose
routes/Route handlers (execute, containers, tools, agents, health, metrics)
authBearer token middleware with constant-time comparison
configTOML config loading and defaults
stateAppState — shared state (engine, manager, store, scanner)
metricsPrometheus recorder initialization and helpers
proxy_handlerPer-container proxy request forwarding
container_proxyContainer-level proxy configuration

§License

MIT

Re-exports§

pub use config::ClawboxConfig;
pub use config::ImageTemplate;
pub use config::ImagesConfig;
pub use config::ToolsConfig;
pub use state::AppState;

Modules§

auth
Bearer token authentication middleware.
config
Configuration loading for clawbox.
container_proxy
Spawns per-container proxy listeners. Each container gets a dedicated Unix socket proxy that enforces its specific allowlist and credential injection rules. Containers have no network access and can only reach the outside world through this socket.
metrics
Prometheus metrics for clawbox.
proxy_handler
Bridge between WASM host_call (sync) and ProxyService (async).
routes
HTTP route handlers for the clawbox API.
state
Shared application state.

Functions§

build_router
Build the axum router with all routes.
spawn_unix_listener
Spawn a Unix domain socket listener serving the same router.