How MiniMax Code Runs Mini Apps: Package, Processes, Lifecycle, and the Agent Bridge
A Mini App’s runtime contract with the MiniMax Code desktop host fits in one function signature: export async function start(context). Behind that entry point, cq-viewer runs a Three.js CAD viewport backed by local Python workers.
Our launch post covered why we built Mini Apps as live workbenches alongside chat. This post looks inside the runtime behind them, from loading a package to serving its page and exchanging calls with the Agent.
One fact shapes most of the design: a Mini App’s Node process is not inside an OS sandbox. It runs as the logged-in user, reads and writes local files, and spawns child processes.
1. One package, four kinds of process, three trust zones
A Mini App is an ordinary MiniMax Plugin with one more manifest. .minimax-plugin/plugin.json names the plugin, and miniapp/miniapp.json declares the Node entry, the page route, any MCP endpoints, and the access the Mini App needs. The runtime payload is exactly two directories, miniapp/client and miniapp/node. The same package can also ship Skills, subagents, and ordinary MCP servers, which the plugin system publishes the way it publishes them for any other plugin.
At runtime that package spreads across four kinds of process (Figure 1):
- The Electron main process owns the tab that holds the page, in the conversation side panel or a pop-out window. It sets the tab’s preload script, works out which Mini App is calling when the page uses the bridge, and adds the loopback token to the page’s own requests.
- A Chromium renderer process runs the page itself, sandboxed and with context isolation. The preload script runs there too and exposes the bridge,
window.mcode.miniapp, to the page’s top-level document. - The local runtime, an Electron utility process, publishes plugins and starts, stops, and counts Mini App processes. It also runs the Agent and tool gateways, hosts the shared MCP runtime, and decides what to reclaim when memory runs short.
- One Node process per running Mini App. The local runtime spawns the Electron binary with
ELECTRON_RUN_AS_NODE=1and a Host runner script. The runner installs the loopback check, imports the plugin’s entry, and callsstart(context). The Host and this process talk over a Node IPC channel opened at spawn time.

Figure 1. The processes behind a Mini App, grouped into trust zones. The circled numbers are referenced in the text.
Those processes fall into three trust zones. The split keeps account credentials, loopback port access, process lifetime, and Agent permissions with the Host, and leaves the plugin free to choose its own stack.
- The Presentation Zone is the page in its renderer. It holds no Host credentials and has no filesystem access; even the loopback token on its own requests is added by the main process (Section 6). It talks to its own Node backend over same-origin HTTP and WebSockets (①) and calls the bridge in its top-level document (④).
- The Application Zone is the Node process, started on demand under the user’s OS account. It serves the page, runs domain logic, writes durable state to an opaque
context.dataDirdirectory, spawns any local CLI workers it needs, and optionally serves Streamable HTTP MCP routes on the same listener. - The Host Zone is the main process plus the local runtime. The Host assigns the loopback port, guards incoming HTTP traffic, starts and reclaims Mini App processes, holds the user’s account and Connector credentials, and mediates every Agent or tool call. Its MCP client calls the plugin’s MCP routes (②), and the plugin’s Node code reaches the Host through
context.agentandcontext.toolover IPC (③).
The contract between the Host and the Node process is one function. Here is a shortened extract, adapted from examples/hello-miniapp/miniapp/node/server.mjs:
import { readFile } from 'node:fs/promises';import { createServer } from 'node:http';import { join } from 'node:path';
export async function start(context) { const clientEntry = await readFile(join(context.pluginRoot, 'miniapp/client/index.html')); const server = createServer((req, res) => { const url = new URL(req.url ?? '/', 'http://miniapp.local'); if (req.method === 'GET' && url.pathname === '/dashboard') { res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' }); res.end(clientEntry); return; } res.writeHead(404).end(); });
await new Promise((resolve, reject) => { server.once('error', reject); server.listen(context.listen.port, context.listen.host, resolve); });
const dispose = async () => new Promise((r) => server.close(() => r())); context.signal.addEventListener('abort', () => void dispose(), { once: true }); return { dispose };}There is no port discovery, no health-check endpoint, and no auth middleware. Resolving start(context) tells the Host the server is listening. Host and Node exchange messages over the IPC channel, not stdio: stdin is ignored, and stdout and stderr only feed a size-capped log, so structured diagnostics belong in context.logger.
2. Lifecycle: from package to running process
Installation does not start a process
Installing or enabling a Mini App, or syncing it from the marketplace, makes its definition available; none of these starts a process. A process starts only when a user or the Agent asks for one. The Agent’s publish is such a request: it accepts a package from the chat’s workspace or a finished package directory and starts it.
Before every spawn, the Host creates a fresh runtime directory, copies the accepted package into it, and verifies the copy against the accepted identity and digest. The process runs from that copy. Edits in the chat’s workspace take effect only after the next publish. Edits to the installed package itself do not slip into the next run: a restart copies and verifies it again, and if it no longer matches what was accepted, the Host refuses to start it.
Starting on demand
A Mini App starts in three ways:
- The user opens it.
- The user @-mentions it in the chat input. The Host starts its backend while the user is still typing, and when the message is sent, it waits until the Mini App’s MCP tools are ready for that turn.
- The Agent opens, publishes, or restarts it through its
miniapptool, which can also list, inspect, and stop Mini Apps.
A Mini App’s MCP endpoints are published only while its process runs, so the Agent sees its tools only then.
Each plugin has at most one Node process. The Host runs at most K_device Mini Apps at once, derived from physical memory: K_device = clamp(⌊3 × M / 8⌋, 3, 10), where M is RAM in GiB, rounded first. That gives 3 on an 8 GB machine, 6 at 16 GB, and 10 from 32 GB up.
A new process counts as ready after three signals: start(context) resolves, the runner reports started over IPC for the current process generation, and the Host’s loopback probe passes (Section 3).
Updating
What happens on update depends on what changed. If only Skills, ordinary MCP servers, or display information changed, the running process keeps serving. If the Node code, the declared access, the MCP endpoints, the client assets, or the page route or window changed, the process has to be replaced.
A marketplace update never replaces a running Mini App by itself; the old version keeps running until the user applies the update. A replacement waits for the old process to exit before the new one starts, so one plugin never has two processes at once.
Reclaim and stop
To keep twenty installed Mini Apps from pinning twenty Node processes and Chromium renderers in RAM, the Host keeps to that cap and reclaims the rest without asking.
It reclaims in two situations. When the user opens a Mini App at the cap, the Host stops the least recently used Mini App that is not in use. When the system runs short of memory, it destroys hidden pages first and stops whole Mini Apps only under critical pressure. Polling, WebSocket traffic, and timers do not count as use.
Reclaim never stops a Mini App the user can see, one the current chat turn mentions with @, one whose MCP tools the Agent is calling, or one started less than a minute ago. A Mini App whose Node code has a Host request in flight, such as an Agent turn or a tool call, or finished one in the last 10 minutes, is never stopped to make room at the cap. Under critical memory pressure it can still be stopped, but only after hidden pages and the Mini Apps with no recent Host request.
A stop runs in a fixed order. The Host aborts context.signal and gives dispose() up to 2 seconds. It then sends SIGTERM, which already ends the process on Windows; elsewhere a force-kill follows 2 seconds later. Only the entry Node process is terminated. The Host does not look for processes the entry spawned.
Crash-only state
Because a hidden page or an idle process can vanish without a callback, plugins have to be written as crash-only software. Durable state belongs in context.dataDir, written as it changes with a temp file and a rename, or with SQLite, and never left for dispose(). If power loss matters, flush the temp file before the rename. Pages save view state when visibilitychange reports hidden, not in beforeunload. dispose() has to kill any Python or ffmpeg workers it spawned, inside the same 2-second window.
3. One node:http entry, any stack behind it
Requiring every Mini App to start through an ES module on node:http is a deliberate bottleneck. Before importing the entry, the runner replaces emit on http.Server.prototype, so every node:http server the plugin creates afterwards inherits a loopback check (Section 6 covers what it checks).
The readiness probe depends on that check. The Host sends GET /__mavis/health to the assigned port twice: once without the token, which must get 401, and once with it, which must get 204. The check answers both itself, before any plugin route runs. That is also why the /__mavis/ prefix is reserved.
If a plugin binds the assigned port with https, http2, tls, raw node:net, or a Python/Go child process, none of those servers inherit from http.Server.prototype, so the check does not run on the port. A server that does not answer the two probes that way does not pass readiness, and the Mini App does not start. Once node:http owns the front door, however, the plugin can run almost anything behind it.
Reverse-proxying full runtimes (openfilm)
openfilm packages the open-source OpenFilm video studio, including both its web editor and its desktop chat/agent handlers, inside a Mini App without modifying upstream OpenFilm. Its server.mjs shows why the node:http front door matters in practice. Figure 2 traces a request through it; its circled numbers match the list below.

Figure 2. The openfilm entry checks each Studio request against an allowlist and adds the Studio key on the server side.
- Ephemeral upstream port and isolated data directory: rather than running
openfilm open(which would collide with or hijack a user’s standalone OpenFilm instance), the Node entry spawns Studio in a child Node process, calling upstream’sstartStudiowithport: 0and its own data directory, by default undercontext.dataDir. The entry then reads the OS-assigned port andx-studio-keyback from therun.jsonStudio writes. - Route and method allowlisting: the
node:httpserver oncontext.listen.portdoes not blindly pipe traffic to Studio. It checks every/api/*request againstSTUDIO_API_ALLOW(24 route prefixes and their exact HTTP methods, such asGET/POST /api/projectsandGET /api/files). Paid media generation (/api/get), service key management (/api/providers), and process lifecycle routes (/api/quit,/api/update) are omitted and rejected with403. - Server-side secret attachment: the upstream
x-studio-keynever reaches HTML, client JavaScript, or iframe URLs. When forwarding an allowed request,studioHeaders()strips incoming cookies and auth headers, and passes through onlyaccept,content-type, andrange. It also setsOriginto Studio’s origin, attachesx-studio-keyon the server side, and rewrites Studio’s secondary preview origin back to the Mini App’s own origin so the browser stays same-origin throughout.
Any Python, Go, Java, or Rust backend follows the same contract: bind 127.0.0.1:0 internally, and let the Mini App’s node:http entry proxy the routes the UI needs.
Workers and vendored frontends
Plugins that do not need a long-running secondary server spawn short-lived workers or ship self-contained web assets:
- Array-argument CLI workers: when cq-viewer opens a
.stepfile, its runChild() helper spawnspython3with[step_mesh.py, file, tmpMesh](no shell interpolation) andstdio: ['ignore', 'ignore', 'ignore']. Active child processes are tracked in aSetsodispose()or a timeout kills them immediately. cutline drivesffmpegandffprobethe same way. - Because
node_modulesis excluded from installed packages, frontends live entirely underminiapp/client/, from cq-viewer’s vendored Three.js modules to minimax-bot’s build-free ES modules.
4. The page: tabs, windows, and the bridge
Each chat session holds at most one tab per Mini App. Opening the Mini App again selects that tab, and while the same process still serves it, the tab keeps its current route. The Agent’s open can also name a path inside the plugin, such as one record. The Host accepts only a path that starts with a single /, resolves it against the Mini App’s own origin, and checks that the result has not left that origin.
A page can also leave the side panel. surface.window in miniapp.json declares how its pop-out window looks: size, frame, transparency, always-on-top, and click-through. The Host validates these and applies them when the page pops out; alwaysOnTop and clickThrough also cap what the page may switch on later. minimax-pet uses a frameless, transparent, always-on-top window to put a desktop pet over the workspace.
The page reaches the Host only through window.mcode.miniapp, which the preload script exposes in the renderer. Every bridge call goes to the main process, which works out the caller (plugin, run, and chat session) from the tab that sent it, never from anything the page passes in. Agent and tool calls then go on to the local runtime.
Through the bridge a page can run and observe Agent turns, ask the user to always allow tools its Node code calls, transcribe speech it recorded, read the Host’s theme and language, and pop itself out. The calls that touch the Agent, tools, or devices need the matching declaration in miniapp.json (Section 6).
5. Bidirectional Agent integration
Because UI routes and hosted MCP endpoints share one Node process, the Agent and the UI operate on the same in-memory and dataDir state.
Agent to plugin, and plugin to Agent
In the Agent-to-plugin direction, miniapp.json binds an MCP server declared in plugin.json to a local path such as /mcp/cq-viewer. Once the process is ready, the Host rewrites that server’s configuration into an HTTP transport aimed at http://127.0.0.1:<port>/mcp/cq-viewer, with the loopback token in its headers, and hands it to the shared MCP runtime. From then on it is an ordinary MCP server: the shared runtime lists its tools, assigns the names the Agent sees, and makes the calls.
When the Agent calls mcp__cq-viewer__add_model_file, the Host POSTs the JSON-RPC call to that route (② in Figure 1). In cq-viewer/miniapp/node/mcp.mjs, the MCP handler validates the JSON schema and then uses the same validation and folder-registration logic as the UI routes in the same process, so the Agent’s change lands in context.dataDir and shows up in the open Three.js viewport in one hop.
In the reverse direction, a Mini App that declares agentAccess or toolAccess receives context.agent (plus window.mcode.miniapp.agent in the page) and context.tool (③). These Node clients carry their calls over the IPC channel the Host opened at spawn time, not over HTTP. cq-viewer uses context.agent.run() for white-model rendering: the page captures a 1600px clay image of the 3D scene, posts the PNG to Node, and Node starts a background Agent turn that uploads the image and invokes MiniMax image generation to produce a studio render.
Constraints, and who approves
Handing a plugin context.agent gives it an Agent equipped with file, shell, and MCP tools. Two kinds of rules limit what the plugin can do with it: some the Host enforces in its protocol, and the rest only the plugin’s own code can keep.
In protocol, each Mini App gets isolated background sessions hidden from the user’s chat list; it cannot continue another Mini App’s sessions or the user’s own chats (session.read is a separate, read-only grant). The Host also caps how many turns each Mini App runs at once and how many it can start per minute.
When an Agent turn hits a gated tool, it pauses on permission.requested. If the caller neither attached an onEvent handler nor opened the session in the chat side panel via agent.open(sessionId), the Host denies the tool call automatically. Most importantly, agent.reply() accepts only 'allowOnce' or 'deny'; there is no 'allowAlways' in the API, so a plugin cannot turn an Agent approval into a standing rule.
The rest depends on plugin code. On the wire, the Host cannot tell whether agent.reply({ decision: 'allowOnce' }) came from a human clicking “Allow once” in the plugin’s UI or from a rogue onEvent callback auto-approving every prompt. Preventing silent allowOnce replies is a repository rule (docs/security.md), not an IPC proof.
Well-behaved plugins enforce user intent in their own state machine. In cq-viewer/miniapp/node/render.mjs, onEvent records the pending { requestId, sessionId, toolName, reason } on the render job, the page renders an approval card, and the POST handler verifies that the job is in 'approval' state and that the client’s requestId matches before calling agent.reply().
Tool calls from Node take a different path. When context.tool.call() reaches a tool the user’s rules mark as ask, the Host draws its own prompt, naming the Mini App, the tool, and the arguments, with Allow once, Always allow, and Deny. Plugin code cannot answer that prompt; it can only cancel its own call. Cancelling while approval is pending withdraws the prompt, and the tool does not run. Cancelling after the call has been dispatched does not guarantee that the tool has not run. Choosing Always allow writes a global allow rule for the whole tool, into the same rule store the chat approval card uses. So a standing rule can come out of a Mini App’s tool call, but only the user can create it.
6. Boundaries and permissions
Two Host mechanisms keep the zones apart while a Mini App runs: the loopback guard on its port, and the permission switches on its declared access.
Loopback port guard
Binding to 127.0.0.1 stops remote network packets, not local ones: any process running under the same OS user, any ordinary browser tab making cross-origin requests, or a page exploiting DNS rebinding can still open a TCP connection to a localhost port.
Those callers can reach context.listen.port at the TCP layer. That is why the runner patches node:http inside the Mini App process before the entry loads, and checks every request on every node:http server there:
- The credential is a random token issued for each process run. It is not one of the user’s account credentials, and the page never handles it. The Electron main process adds it at the network layer. It does so only for requests that come from a registered Mini App tab, go to that tab’s own origin (
http://127.0.0.1:<port>), and start in the top-level frame or a frame already on that origin. A foreign iframe inside the page cannot borrow the token, and page scripts cannot read it. The Host’s MCP client sends the same token in the headers of its HTTP transport. - A request passes only if its
Hostheader is exactly127.0.0.1:<port>and it carries the current token, compared in constant time. Anything else gets401before the plugin’s request listener runs. A WebSocket upgrade orCONNECTthat fails the check has its socket destroyed. - On requests that pass, the check deletes the token from both
headersandrawHeaders, so route handlers, proxies, and loggers never see it. Every new process gets a new token. The main process holds it, and when the Mini App is started, updated, opened, or refreshed, it updates the authentication binding of the Mini App’s already-open tabs on the same origin to the new token.
A DNS-rebinding page fails both conditions. Its requests carry the attacker’s hostname in Host, and because it is not a registered Mini App tab, the main process never adds the token.
The guard is installed inside the plugin’s own process. It keeps outside callers away from the plugin’s routes; it does not constrain the plugin’s code, which already runs with the user’s privileges.
Every node:http server in the process inherits the check, so a plugin cannot open a side door on a second port. The check looks at the Host header and the token, not at the port a request arrived on. Ordinary callers of a second port still get 401: a browser puts that port in Host, and neither the main process nor the MCP client sends the token anywhere but the assigned origin.
Static manifest checks, and live switches
Every capability beyond serving HTTP (agentAccess, toolAccess, deviceAccess for microphone, camera, and notifications, and hostAccess for navigation.read) is gated in two separate places that serve different purposes:
- Repository hygiene (
npm run check): scripts/lib/rules/usage.mjs scans the payload’s source text with regular expressions and flags calls to a capability the manifest does not declare (ACCESS_UNDECLARED). Aliasing a variable can evade it, and dead code in a vendored bundle can trip it. It is a fast lint gate for contributors, not a security sandbox. - Runtime enforcement and live switches: actual enforcement lives in the Host. Undeclared capabilities are absent or rejected at runtime, browser permission prompts are suppressed in favor of manifest declarations, and users can toggle any declared permission off in the plugin details view while the Mini App is running. Flipping a switch does not restart the Node process:
context.agentandcontext.toolstay defined, and subsequent calls immediately reject withNOT_PERMITTED,TOOL_NOT_PERMITTED, orNotAllowedErroruntil toggled back on. Switching offsession.runalso aborts any turn that is already running. A microphone or camera stream that is already open keeps running until the page stops it.
The architecture in one pass
A Mini App is a plugin package with a page and a Node entry. The Host keeps the package as a definition until a user or the Agent asks for it. It then runs the package from a verified copy, in one Node process per plugin under a device-wide cap, and reclaims that process when it goes unused. Every backend, whatever its stack, sits behind one node:http entry that the Host guards and probes. The page lives in a sandboxed renderer and reaches the Host only through the bridge. The Agent reaches the plugin through hosted MCP, and the plugin reaches the Agent and the user’s tools over IPC.
Throughout, the plugin’s Node code runs with the user’s local privileges, so install Mini Apps from authors you trust. What the Host keeps for itself is narrower: account credentials, the loopback port, process lifetime, and the approvals and switches that let users revoke Agent, tool, or device access while the workbench keeps running.
Explore the runtime and source
git clone https://github.com/MiniMax-AI/MiniMax-Code-MiniApps.gitcd MiniMax-Code-MiniApps && npm run check- Contract & runtime specs: docs/package-contract.md · docs/runtime.md · docs/client.md · docs/agent.md · docs/tool.md · docs/security.md
- Code referenced in this post: examples/hello-miniapp/ · cq-viewer · openfilm · minimax-bot · minimax-pet · scripts/lib/rules/
- Missing a runtime capability? Add your use case to the pinned capability wishlist (Issue #9).