# legend-of-alan/ghostmode architecture

> Architecture diagram of the GitHub repository legend-of-alan/ghostmode, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/legend-of-alan/ghostmode
- Repository: https://github.com/legend-of-alan/ghostmode

## Overview

Ghost Mode is a Rust library that lets an agent run a Python script against host tools through a sandbox, returning only the script's result. The documented workflow is: expose execute/poll schemas to the model, pass execute or poll requests to Sandbox, run scripts through a Monty backend, dispatch script tool calls to the Host, and return a bounded Status. The README also documents MCP host integration, alternative schema formats, resource limits, polling, session dump/restore, and signing. Edges follow the excerpts or README; unsampled implementation details are not inferred.

Main entry points: [`src/sandbox.rs`](https://github.com/legend-of-alan/ghostmode/blob/main/src/sandbox.rs) (Sandbox API), [`src/backend/monty.rs`](https://github.com/legend-of-alan/ghostmode/blob/main/src/backend/monty.rs) (Monty backends), [`src/mcp.rs`](https://github.com/legend-of-alan/ghostmode/blob/main/src/mcp.rs) (MCP host), [`src/host.rs`](https://github.com/legend-of-alan/ghostmode/blob/main/src/host.rs) (Host interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Agent API"]
  node_schemas["Tool schemas<br/>[schema.rs]"]
  node_sandbox["Sandbox API<br/>[sandbox.rs]"]
  node_status["Run status<br/>[sandbox.rs]"]
  node_output_budget["Output budgeting<br/>[output.rs]"]
end

subgraph group_runtime["Script runtime"]
  node_backend_trait["Backend contract<br/>[backend.rs]"]
  node_monty_config["Monty backends<br/>[monty.rs]"]
  node_in_process["In-process runner<br/>[in_process.rs]"]
  node_worker_pool["Worker pool runner<br/>[pool.rs]"]
  node_value_conversion["Value conversion<br/>[value.rs]"]
end

subgraph group_tools["Host tools"]
  node_host["Host interface<br/>[host.rs]"]
  node_mcp_host["MCP host<br/>[mcp.rs]"]
end

subgraph group_sessions["Session state"]
  node_session_dump["Session dump<br/>[sandbox.rs]"]
  node_signing["Dump signing<br/>[sandbox.rs]"]
end

node_model(("Agent model"))
node_caller(("Agent caller"))
node_mcp_server["MCP server"]

node_caller -->|"gets definitions"| node_schemas
node_schemas -->|"provides functions"| node_model
node_caller -->|"passes requests"| node_sandbox
node_sandbox -->|"runs scripts"| node_backend_trait
node_backend_trait -->|"implemented by"| node_monty_config
node_monty_config -->|"selects runner"| node_in_process
node_monty_config -->|"selects runner"| node_worker_pool
node_in_process -->|"converts calls"| node_value_conversion
node_worker_pool -->|"converts calls"| node_value_conversion
node_sandbox -->|"dispatches calls"| node_host
node_host -->|"returns answers"| node_sandbox
node_sandbox -->|"bounds output"| node_output_budget
node_sandbox -->|"returns status"| node_status
node_status -->|"sent to model"| node_caller
node_sandbox -->|"dumps sessions"| node_session_dump
node_session_dump -->|"restores sessions"| node_sandbox
node_signing -->|"authenticates bytes"| node_session_dump
node_mcp_host -->|"implements interface"| node_host
node_mcp_host -->|"calls tools"| node_mcp_server
node_caller -.->|"configures host"| node_mcp_host

click node_schemas "https://github.com/legend-of-alan/ghostmode/blob/main/src/schema.rs"
click node_sandbox "https://github.com/legend-of-alan/ghostmode/blob/main/src/sandbox.rs"
click node_status "https://github.com/legend-of-alan/ghostmode/blob/main/src/sandbox.rs"
click node_host "https://github.com/legend-of-alan/ghostmode/blob/main/src/host.rs"
click node_mcp_host "https://github.com/legend-of-alan/ghostmode/blob/main/src/mcp.rs"
click node_backend_trait "https://github.com/legend-of-alan/ghostmode/blob/main/src/backend.rs"
click node_monty_config "https://github.com/legend-of-alan/ghostmode/blob/main/src/backend/monty.rs"
click node_in_process "https://github.com/legend-of-alan/ghostmode/blob/main/src/backend/monty/in_process.rs"
click node_worker_pool "https://github.com/legend-of-alan/ghostmode/blob/main/src/backend/monty/pool.rs"
click node_value_conversion "https://github.com/legend-of-alan/ghostmode/blob/main/src/backend/monty/value.rs"
click node_output_budget "https://github.com/legend-of-alan/ghostmode/blob/main/src/sandbox/output.rs"
click node_session_dump "https://github.com/legend-of-alan/ghostmode/blob/main/src/sandbox.rs"
click node_signing "https://github.com/legend-of-alan/ghostmode/blob/main/src/sandbox.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_schemas,node_sandbox,node_status,node_output_budget toneBlue
class node_backend_trait,node_monty_config,node_in_process,node_worker_pool,node_value_conversion toneAmber
class node_host,node_mcp_host,node_mcp_server toneMint
class node_session_dump,node_signing toneRose
class node_model,node_caller toneIndigo
```

## Components

### Agent API

- [Tool schemas](https://github.com/legend-of-alan/ghostmode/blob/main/src/schema.rs): `src/schema.rs`
- [Sandbox API](https://github.com/legend-of-alan/ghostmode/blob/main/src/sandbox.rs): `src/sandbox.rs`
- [Run status](https://github.com/legend-of-alan/ghostmode/blob/main/src/sandbox.rs): `src/sandbox.rs`
- [Output budgeting](https://github.com/legend-of-alan/ghostmode/blob/main/src/sandbox/output.rs): `src/sandbox/output.rs`

### Script runtime

- [Backend contract](https://github.com/legend-of-alan/ghostmode/blob/main/src/backend.rs): `src/backend.rs`
- [Monty backends](https://github.com/legend-of-alan/ghostmode/blob/main/src/backend/monty.rs): `src/backend/monty.rs`
- [In-process runner](https://github.com/legend-of-alan/ghostmode/blob/main/src/backend/monty/in_process.rs): `src/backend/monty/in_process.rs`
- [Worker pool runner](https://github.com/legend-of-alan/ghostmode/blob/main/src/backend/monty/pool.rs): `src/backend/monty/pool.rs`
- [Value conversion](https://github.com/legend-of-alan/ghostmode/blob/main/src/backend/monty/value.rs): `src/backend/monty/value.rs`

### Host tools

- [Host interface](https://github.com/legend-of-alan/ghostmode/blob/main/src/host.rs): `src/host.rs`
- [MCP host](https://github.com/legend-of-alan/ghostmode/blob/main/src/mcp.rs): `src/mcp.rs`

### Session state

- [Session dump](https://github.com/legend-of-alan/ghostmode/blob/main/src/sandbox.rs): `src/sandbox.rs`
- [Dump signing](https://github.com/legend-of-alan/ghostmode/blob/main/src/sandbox.rs): `src/sandbox.rs`

### Other components

- **Agent model**
- **Agent caller**
- **MCP server**

## Connections

- Agent caller → Tool schemas: gets definitions (evidence: `README.md`)
- Tool schemas → Agent model: provides functions (evidence: `README.md`)
- Agent caller → Sandbox API: passes requests (evidence: `README.md`)
- Sandbox API → Backend contract: runs scripts (evidence: `src/backend.rs`)
- Backend contract → Monty backends: implemented by (evidence: `src/backend.rs`)
- Monty backends → In-process runner: selects runner (evidence: `src/backend/monty.rs`)
- Monty backends → Worker pool runner: selects runner (evidence: `src/backend/monty.rs`)
- In-process runner → Value conversion: converts calls (evidence: `src/backend/monty/in_process.rs`)
- Worker pool runner → Value conversion: converts calls (evidence: `src/backend/monty/pool.rs`)
- Sandbox API → Host interface: dispatches calls (evidence: `README.md`)
- Host interface → Sandbox API: returns answers (evidence: `README.md`)
- Sandbox API → Output budgeting: bounds output (evidence: `src/sandbox.rs`)
- Sandbox API → Run status: returns status (evidence: `README.md`)
- Run status → Agent caller: sent to model (evidence: `README.md`)
- Sandbox API → Session dump: dumps sessions (evidence: `src/sandbox.rs`)
- Session dump → Sandbox API: restores sessions (evidence: `src/sandbox.rs`)
- Dump signing → Session dump: authenticates bytes (evidence: `src/sandbox.rs`)
- MCP host → Host interface: implements interface (evidence: `src/mcp.rs`)
- MCP host → MCP server: calls tools (evidence: `src/mcp.rs`)
- Agent caller → MCP host: configures host (evidence: `README.md`)
