AI Infrastructure & Runtime

Building an AI Employee Runtime From the Ground Up

A runtime is the layer that decides what an AI employee is allowed to do, what gets recorded, and what happens when a step fails.

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

Direct Answer (Quick Summary)

An AI employee runtime is the layer that turns a model response into work with consequences: a durable queue, an isolated execution sandbox, a tool gateway that scopes access, persistent state, a budget meter and an approval channel. The model decides what to do next. The runtime decides what is permitted, what is recorded, and what happens when a step fails.

Key Takeaways

  • A runtime needs six components: a durable task queue, an isolated sandbox, a tool gateway, a state store, a budget meter and an append-only audit sink.
  • The execution loop is fixed order: claim work, load role and context, call the model, validate and gate each tool call, resolve or escalate, commit state, release the lease.
  • Credentials are injected by the tool gateway, never placed in the model context, so a confused agent cannot read a secret it did not need.
  • Retry policy, budgeting, completion status and loop limits belong to the runtime because the model cannot be trusted to police its own execution.
  • A single model call is not a runtime: it has no approvals, no tenancy isolation, no budget enforcement and no replayable log.
  • A script plus a scheduler is the correct answer for one internal workflow; the runtime pays for itself at the second workflow and the first external write.
  • Observability is a runtime requirement, not a dashboard feature, because the events must exist to be displayed.

An AI employee runtime is the layer that turns a model response into work with consequences: a durable queue, an isolated sandbox, a tool gateway that scopes access, persistent state, a budget meter and an approval channel. The model decides what to do next. The runtime decides what is permitted, what gets recorded, and what happens when a step fails.

That split is the whole design. Everything below follows from it.

The six components

ComponentResponsibilityWhat breaks without it
Task queueDurable, retryable work that survives a restartIn-flight work is lost when the worker dies
Execution sandboxIsolated process or container with its own filesystem and clockOne runaway loop takes down everything else
Tool gatewayMediates every external call and injects credentialsThe model holds secrets it can leak or misuse
State storePer-item progress, memory, durable artifactsPartial work is invisible and reruns duplicate it
Budget meterCounts cost per employee and hard-stopsRunaway spend is discovered on an invoice
Audit sinkAppend-only stream of every eventYou cannot answer what it did last Tuesday

None of these are the model. That is the recurring point in why models alone are not enough for enterprise AI and AI employees need more than LLMs.

The execution loop, in order

  1. Claim a unit of work with a lease, so two workers never process the same run.
  2. Load the employee role, its policies and only the context relevant to this item.
  3. Call the model with the tool list that employee is scoped to, and nothing else.
  4. On a tool call: validate arguments, check policy, execute, append an event.
  5. Repeat until the employee returns a result or the step ceiling is hit.
  6. If the result is an irreversible write, park it in the review queue with its evidence attached.
  7. Commit the state transition, release the lease, emit metrics.

Pseudocode, roughly:

const run = await queue.claim({ leaseSeconds: 300 })
await state.start(run)

for (let step = 0; step < limits.maxSteps; step += 1) {
  const decision = await model.next({ role: employee.role, tools: employee.tools, state: state.context() })

  if (decision.type === 'tool') {
    await audit.append({ run, step, tool: decision.name, args: decision.args })
    const verdict = gateway.check(decision)
    if (verdict === 'deny') return state.fail(run, 'policy')
    if (verdict === 'needs_approval') return state.propose(run, decision)
    decision.result = await gateway.execute(decision)
    continue
  }

  return state.complete(run, decision)
}

return state.escalate(run, 'step ceiling reached')

The needs_approval branch is what makes the loop safe to run unattended, and it is the same mechanism described in human approval in AI workflows.

What the model must never be trusted with

  • Secrets. Credentials are injected by the gateway at call time. They are never in the prompt, so a confused agent cannot read one it did not need.
  • Retry policy. The runtime retries with backoff. A model deciding to retry can turn a five-minute blip into an afternoon.
  • Budget. The model may request work; the meter decides whether it is affordable.
  • Direct database writes. Writes go through a validated API or query layer that enforces schema, scoping and idempotency.
  • Its own completion status. A run is complete when the last step actually succeeded, not when the model says so.

Why a model call is not a runtime

You can call a model from a script in an afternoon, and for a lot of experiments that is entirely the right thing to do. What you do not get from the model API is approvals, tenant isolation, budget enforcement, durable state or a replayable log. Each of those is a component above, and each is exactly what separates a demo from something a compliance team will sign off on. The layer described in the infrastructure behind AI employees and what infrastructure AI employees need is that layer in full.

Tools are the other half of the story. The distinction between a tool call and an MCP connection is covered in what MCP is and why it matters for AI employees, because how an employee reaches a system determines how much of the gateway you need.

Build or adopt

If you have one internal workflow, one user and no external writes, build it. A script with a scheduler and a small table of results is cheaper, faster to understand and easier to delete. That is the honest case for the script, and it is where enterprise AI build vs buy usually starts.

Adopt or extend a runtime when one of these becomes true: you have a second workflow and the first one is now a dependency rather than a script; you have external writes and need an approval gate; you have more than one team whose data must stay separated; or an auditor has asked a question you cannot answer. The line between the two products is drawn in AI models vs AI operating systems.

What the runtime must emit

Every event carries the run id, the employee, the step number, the tool and arguments, the approval decision, the artifact produced, the cost so far and the outcome. Without those fields, monitoring degrades into reading logs. With them, AI observability for AI employees and monitoring AI employee executions are both views over the same stream, which is the only way the two stay consistent.

How to apply this

  1. Write the execution loop as code before you write any prompts. The loop is the stable part.
  2. Put the tool gateway in front of every external system on the first day, even with a single employee.
  3. Track state per item and add an idempotency key before the first irreversible write.
  4. Add the budget meter and set the ceiling in currency, not tokens.
  5. Emit one event per step from the beginning; retrofitting an audit trail is painful and usually incomplete.
  6. Only then add the model, and keep the model out of the decisions that matter.

Sources and further reading

Frequently Asked Questions

What is an AI employee runtime?

It is the execution layer between a model and the systems an AI employee touches. It provides a durable task queue, an isolated sandbox, a tool gateway that scopes access and injects credentials, persistent per-item state, a budget meter and an approval channel. The model chooses the next action; the runtime enforces what is allowed, records what happened and decides what happens when a step fails.

Do I need a runtime if I only have one AI workflow?

Probably not yet. One internal workflow with no external writes and one user is a reasonable place for a script plus a scheduler, and it will be simpler to understand and to delete. The runtime becomes worth it at the second workflow that depends on the first, the first irreversible external write, the first requirement to separate two teams' data, or the first auditor question you cannot answer from logs.

How should a runtime handle retries?

The runtime should retry, not the model, using bounded attempts with backoff and a step ceiling, then escalate to a human rather than looping. Model-decided retries are how a transient outage turns into a full day of spend. Every write must also be idempotent, keyed on the item itself, so a replay produces the same result instead of a duplicate record.

Where do API keys and secrets belong in a runtime?

In the tool gateway, injected at call time, never in the model context. If a credential is not in the prompt, a confused or manipulated agent cannot read or exfiltrate it. The gateway should also scope what each credential can reach, so an employee that only needs to read a system never receives a write-capable token in the first place.

How much of a runtime is observability?

All of it, and it has to exist before the dashboard does. If the runtime does not emit a structured event per step, with run id, tool, arguments, approval and outcome, monitoring is log reading and cost attribution is guesswork. Build the event stream first; the dashboards are then just different queries over data you already have.

Related reading