AI Infrastructure & Runtime

The Infrastructure Layer Behind AI Employees

What actually has to exist for an AI employee to be trustworthy: five subsystems, a three-outcome gate, and a memory layer scoped twice.

By Hitank Shah • 11 min read • Updated 2026-11-08

Direct Answer (Quick Summary)

The infrastructure layer behind an AI employee is five subsystems — a model loop, a sandbox pool, a credential vault resolver, an MCP tool dispatcher, and a memory engine — plus a policy gate resolving every action to "allow", "deny", or "pending_approval". The model supplies reasoning; the layer supplies state, isolation, authority, and evidence.

Key Takeaways

  • A model is a reasoning processor: no memory between calls, no filesystem, no credentials, no self-scheduling.
  • The runtime is five single-responsibility modules (1,735 lines) behind a 1,344-line orchestrator, not one 4,248-line file.
  • Authority is a denylist: an action is refused unless a rule permits it, so new vendor capabilities are inert by default.
  • The model never holds a raw secret. It requests an action; the dispatcher acts with a credential it cannot print.
  • Memory is scoped twice — by org AND by employee — so one employee never reads another’s working notes.
  • Trustworthiness is a state machine with named states, not a prompt instruction.

The model is the easy part

Here is the uncomfortable truth about AI employees: the language model is the smallest and least interesting part of the system.

A frontier model is a reasoning processor. Ask it the same question twice and it has no memory of the first time. Ask it to read a file and it cannot. Give it an API key and it has no way to use one safely — and no way to know that using one is consequential.

Everything that makes an AI employee usable lives outside the model. The model decides what to do next. The infrastructure decides what it is allowed to do, what it remembers, and what happens afterwards.

This article is about that layer, described against the OneCo codebase so you can check every number.

Five subsystems, one orchestrator

The execution engine used to be a single 4,248-line file. Every change risked breaking something unrelated, and no subsystem could be tested or replaced in isolation. It was decomposed into five modules with one job each, behind an orchestrator that only wires them together.

ModuleLinesResponsibility
server/execution/model-loop.js639Multi-agent iteration: goal planning, task assignment, iteration scheduling
server/execution/mcp-dispatcher.js415Tool routing, schema validation, auto-allow evaluation, timeouts, truncation
server/execution/memory-engine.js359Vector retrieval, session summarisation, transcript building
server/execution/sandbox-pool.js194Container lifecycle, per-org pooling, idle sweeping
server/execution/vault-resolver.js128Credential decryption, token refresh
server/worker.js1,344Orchestration only

The line counts are less important than the boundaries. Each module can now fail in one place, be tested alone, and be replaced without a rewrite. worker.js went from being the system to being a wiring diagram.

1. The model loop decides what happens next

model-loop.js runs the multi-agent iteration: plan a goal, decompose it into tasks, assign them to employees, schedule the next iteration.

The design constraint is that this module must not know how anything is executed. It emits intent; a different module decides whether that intent is permitted. That separation is what makes the approval gate possible at all. If planning and execution were tangled together, you could not insert a gate between them without rewriting the planner.

2. Sandboxes supply isolation no prompt can

sandbox-pool.js owns every Docker container. It exposes a DockerSandbox class for lifecycle, and a per-org pool (orgContainerPool) so two sessions from the same organisation reuse a warm container instead of paying cold-start on every run.

The pool has a sweeper. startContainerPoolSweeper() reaps containers idle beyond a threshold. Without it, a fleet of abandoned containers is a slow, silent, expensive leak.

Two details worth stealing:

  • BlockedExecutionError is a distinct error class, not a message string. A blocked execution is a first-class outcome, not an error to be parsed. That is the difference between a policy you can enforce and one you can only log.
  • makeNoopSandbox() returns a sandbox that does nothing. Dry runs, tests, and preview modes all use it. If your system cannot run without a container, you cannot test the parts that run before the container starts.

3. The vault keeps authority out of the model's reach

vault-resolver.js decrypts credentials and refreshes tokens. The critical property is negative: the model never holds a raw secret. It asks for an action; the dispatcher acts with a credential the model has never seen and cannot print.

This is the single highest-leverage security decision in the whole layer. An AI employee that can read its own API key is a credential-exfiltration incident waiting to happen — prompt injection becomes credential exfiltration. One that can only request an action against a scoped credential is not.

4. The dispatcher is where authority is actually decided

mcp-dispatcher.js routes a tool call to a connector. Four functions do the real work:

~~~js export async function evaluateAutoAllowRules(toolName, input, sandboxId, agentId, orgId, loadStateFn = null) export async function getMcpSchema(connector, orgId, redisClient = null, supabaseClient = null) export async function executeMcpTool(connector, toolName, toolInput, orgId, opts = {}) export function matchGlob(str, pattern) ~~~

Read evaluateAutoAllowRules closely, because the policy is inverted from what most teams build. The default is deny, and rules are evaluated to find permission — not to find prohibition. An action with no matching rule stops. A tool the platform has never heard of is inert by default.

That is the difference between a denylist and an allowlist, and it is not a stylistic preference. With a denylist, every new capability your vendors ship is already permitted the moment you connect them. With an allowlist, it is refused until someone decides otherwise. One of those fails silently; the other fails loudly and safely.

Tool results are also truncated. A 50 KB response is not more useful than a 2 KB one — it is more likely to blow the context window, more expensive, and more likely to contain something that reads like an instruction rather than data.

5. Memory is retrieval, and it is scoped twice

memory-engine.js exports retrieval, summarisation, and award functions:

~~~js export async function retrieveKnowledgeContext(orgId, agentId, query, topK = 8, client = null) export async function retrieveMemoryContext(orgId, agentId, query, topK = 5, client = null) export async function summarizeSession(transcript, agentMeta, userKeys, opts = {}) export function cosineSimilarityForWorker(a, b) ~~~

Note the signatures. Every retrieval takes both orgId and agentId. Memory is scoped twice: once by tenant, once by employee. An employee never sees another employee's memory even inside the same organisation, because the alternative is an organisation where every employee implicitly reads every other employee's working notes.

summarizeSession then compacts the transcript and buildSessionTranscript assembles it. Memory is not a transcript archive. A summary is an abstraction with a cost, and knowing what you are willing to lose in that compression is part of the design.

The gate: a state machine, not a warning

Authority decisions resolve to exactly three outcomes — "allow", "deny", or "pending_approval" — each paired with an audit outcome of "allowed", "blocked", or "pending_approval".

Three outcomes, not two, is the important detail. A system that can only allow or deny forces a binary choice on every external write. Adding a third state — wait for a human — is what makes an autonomous system deployable in an organisation with real data in it.

When execution does stop, it stops in a named state machine:

~~~js export const PITSTOP_STATES = Object.freeze({ CREATED: "created", ACKNOWLEDGED: "acknowledged", ASSIGNED: "assigned", WAITING: "waiting", RESOLVED: "resolved", CONTINUATION_DECISION: "continuation_decision", CLOSED: "closed" // closed without resolution (escalation, abandonment) }); ~~~

A human approving a push is not a boolean. It is a transition through states that can be acknowledged, assigned, waited on, escalated, and abandoned — each transition recorded. When someone asks six weeks later "who approved this, and when?", the answer is a row, not a reconstruction.

The composite: what trustworthiness is made of

Take the parts together and the pattern is consistent: every layer is designed so that failure is a recorded state, not a silent omission.

  • Blocked execution is a typed error, not a string.
  • Unauthorised action is deny, not an unhandled crash.
  • Waiting for a human is a named state, not a timeout.
  • An out-of-scope origin is refused with a header withheld, not a 500 that takes the page down.
  • A missing status renders as Unknown, not an empty badge.

None of this is visible on a good day. All of it is the difference between a demo and something you would let near a production database.

What to take from this

If you are building this yourself, build in this order:

  1. The gate first. Before you have any tools, decide what allowed, denied, and wait-for-a-human mean, and what gets recorded. Retrofitting a policy layer onto an agent that already holds credentials is miserable.
  2. Never let the model hold a secret. Request-then-act beats give-then-trust by a wide margin.
  3. Default to deny. Retrofitting an allowlist later means auditing everything that already ran.
  4. Scope memory twice. Tenant and employee. Retro-fitting the second scope is a data incident.
  5. Make blocked a first-class outcome. If you cannot represent "this was refused", you cannot count refusals — and unmeasured refusals are how incidents happen quietly.

The model will keep improving. None of the above depends on the model improving.

Sources and further reading

Frequently Asked Questions

Do AI employees need infrastructure, or is the model enough?

The model alone cannot store state, hold credentials, run in isolation, or record what it did. Those are the five subsystems described here, and they are what make an AI employee safe to run near real data.

Why does the model never hold the API key?

Because prompt injection becomes credential exfiltration the moment the model can read its own secret. Requesting an action and letting the dispatcher act with a scoped credential removes that path entirely.

What is the difference between a denylist and an allowlist for tool access?

A denylist permits everything that is not explicitly forbidden, so new vendor capabilities become live the moment you connect them. An allowlist refuses everything not explicitly permitted. The allowlist fails loudly and safely; the denylist fails silently.

Why does memory need to be scoped by both organisation and employee?

Organisation scoping prevents cross-tenant leakage. Employee scoping prevents one employee reading another’s working notes inside the same tenant. Both are needed, and adding the second scope after launch is a data incident rather than a refactor.

Related reading