How to Safely Run AI Agents in Production: A Mission-Critical Architecture
Running an AI coding agent near a mission-critical system is not primarily a prompting problem. It is an architecture and operating-model problem.
This article is for teams deciding whether an agent should be allowed near repositories that contain production code, deployment logic, infrastructure definitions, or release automation. The goal is not to promise perfect safety; it is to define a trust boundary that an architecture review can inspect and challenge.
The agent may be able to read application code, edit deployment manifests, execute shell commands, inspect GitHub, call external services, and prepare changes that eventually reach production. Safety therefore depends on multiple boundaries working together. It also depends on whether the task is reversible, whether the repository contains untrusted content, and whether production credentials are completely absent from the session:
- Reversibility — prefer changes that can be inspected, discarded, or rolled back before external side effects occur.
- Untrusted input — treat issue text, pull requests, logs, generated files, and documentation as data, not instructions that can override policy.
- Credential absence — do not give the agent production credentials merely because the repository is production-facing.
The core controls are:
- Permissions — define what tools may do against which targets.
- Worktrees — isolate changes and preserve a clean review path.
- Modes — control how much interaction and autonomy the session receives.
- Sandboxing — constrain selected command execution and resource usage.
These pillars reduce risk, but they do not create a production guarantee by themselves. Git hosting controls, identity, network policy, secret management, CI, deployment approvals, observability, and incident response remain part of the system.
The architectural question is blast radius
“Can the agent edit the repository?” is too narrow a question for a production environment.
Ask instead:
- What is the maximum filesystem scope of a write?
- Which commands can run without a human checkpoint?
- Can the session see production credentials?
- Can it reach the network, and through which path?
- Can it push, open a pull request, merge, deploy, or alter infrastructure?
- What happens when the model misunderstands the task?
- Which effects are contained by the chosen boundary, and which require a separate operational response?
A useful safety architecture assumes that the agent will eventually make a wrong decision. The design goal is to make that decision visible, bounded, and recoverable before it becomes an outage.
yottacode building blocks
yottacode turns this architecture into concrete controls rather than one broad autonomy switch:
- Permission policy — system, shared project, and local rules decide which tool calls are allowed, require approval, or are denied.
- Workspace and path boundaries — file tools confine writes to the active workspace or explicitly allowed roots, reject unsafe symlink paths by default, and protect sensitive state.
- Managed worktrees — separate branches and directories keep experiments and agent changes away from the primary checkout.
- Session modes — Plan, Normal, Auto, and Yolo make the level of interaction explicit while remaining subject to permissions and hard safety gates.
- Approval surfaces — consequential shell, test, Git, GitHub, commit, rollback, and worktree operations can remain visible to a human.
- Podman command sandbox — selected command and test execution can run in a rootless, resource-limited container with explicit mounts and network settings.
- Git and GitHub boundaries — local history changes, pushes, pull-request writes, and other remote mutations remain separate decisions from repository inspection.
- Traceability and auditability — the built-in
/inspectview exposes turns, tool calls, arguments, approvals, status, latency, usage, and flagged output;yottacode sessions exportproduces Markdown or structured JSONL for local review,jq, diffing, and retention. - Audit records — session state, tracked file mutations, tool activity, approvals, and test results provide evidence for review, while external effects remain outside the file-change boundary. The external system—Git hosting, CI, cloud control plane, or deployment platform—remains the source of truth for remote side effects.
The building blocks are complementary. A worktree without permissions still has too much authority. A sandbox without GitHub controls can still publish a change. Permissions without path validation are not a host boundary. The architecture works when each control is assigned a specific failure mode.
The four pillars of a safe operating model
Pillar 1: Permissions define authority
Permissions are the policy layer that decides which tool calls may run silently, which must ask, and which must never run.
A production policy should be specific to the tool and target. It should distinguish:
- Reading source from editing source.
- Running tests from running arbitrary shell commands.
- Reading Git state from pushing or rewriting history.
- Reading GitHub context from creating or updating remote resources.
- Inspecting infrastructure from changing infrastructure.
The effective precedence is:
Deny > Ask > Allow > session allow > tool defaultThat ordering is important. A broad allow rule must not weaken a higher-priority deny or ask rule. An explicit deny remains enforced even when a session uses Yolo mode.
If a single-shot yottacode run needs to mutate a file and no saved allow rule matches, it cannot pause for an interactive approval. The mutation fails with an approval-required result and the file is not changed. A narrowly scoped saved allow rule is the preferred way to authorize unattended mutation; an ask rule still requires a human prompt and therefore cannot satisfy a noninteractive run.
Permission files can exist at several scopes:
/etc/yottacode/permissions.jsonfor a machine-wide administrator baseline.<repo>/.yottacode/permissions.jsonfor committed team policy.<repo>/.yottacode/permissions.local.jsonfor personal, gitignored rules.
For a mission-critical repository, start with a deny-by-default posture for destructive and external operations. Allow only narrow, repeatable tasks. Require confirmation for publishing, pushing, infrastructure changes, and any action whose blast radius extends beyond the checkout.
A permission rule is not an operating-system sandbox. A Bash(...) rule matches the command descriptor yottacode evaluates; it does not make arbitrary shell indirection, aliases, scripts, or child processes safe. Use sandboxing and outer infrastructure controls when you need host isolation.
Pillar 2: Worktrees isolate change
Do not make the primary checkout the agent’s experimentation surface.
A managed worktree gives the agent a separate directory and branch while keeping the main checkout available for comparison and review. This is especially valuable for:
- Broad refactors.
- Dependency upgrades.
- Generated-code changes.
- CI and deployment-file edits.
- Tasks that may require several implementation attempts.
- Unattended or semi-autonomous runs.
A robust workflow is:
- Create a fresh worktree.
- Inspect the repository and write the plan there.
- Approve the scope before implementation.
- Make changes only inside the worktree.
- Run tests and inspect the complete diff.
- Open a draft pull request rather than merging directly.
- Keep the worktree until review is complete.
Worktrees are not a substitute for permissions. They contain file changes, but they do not automatically contain credentials, network access, GitHub authority, or external side effects.
Also be deliberate with .worktreeinclude. Files copied into a worktree may include environment configuration. A worktree is safer only when the data copied into it is also appropriate for the task.
Pillar 3: Modes control interaction
Modes are session-level operating postures layered on top of persistent permissions.
| Mode | Appropriate use | Boundary |
|---|---|---|
| Plan | Repository research and design before implementation | Read-only research; only the resolved plan file is an automatic write exception. |
| Normal | Interactive implementation | Each tool follows its normal approval behavior. |
| Auto | Narrowly trusted routine work in an isolated workspace | Ordinary edits may auto-approve, but shell, tests, commits, rollback, and worktree transitions remain in the safety floor. |
| Yolo | Exceptional automation in a disposable, reviewed environment | Skips remaining ordinary prompts but does not bypass deny rules, ask rules, path validation, trust, plan restrictions, or hard guards. |
For production-oriented work, the safest default sequence is:
Plan → review scope → Normal implementation → verify → draft PR → human reviewAuto mode can be useful inside a controlled worktree after the scope is understood. It is not an allowlist, and it does not remove the need for permissions, path validation, or review.
Yolo mode should be treated as an exceptional execution overlay, not as a production safety strategy. It does not replace least privilege, sandboxing, branch protection, or deployment approval.
Pillar 4: Sandboxing constrains command execution
The optional Podman sandbox adds an execution boundary for selected command-capable tools. With [sandbox] backend = "podman", run_bash and relevant test/document subprocesses run in a rootless container with the project and managed-worktree paths mounted.
The sandbox applies hardening such as:
- Rootless user namespaces.
- Dropped Linux capabilities.
no-new-privileges.- Resource limits where the host supports them.
- A constrained temporary filesystem.
- Explicit project-relative mounts.
- Fail-closed startup when Podman or the required image cannot run.
A restrictive configuration can use:
[sandbox]
backend = "podman"
network = "none"
memory = "4g"
cpus = 4
pids_limit = 256The important limitation is scope. The sandbox does not place the entire agent inside the container. yottacode itself, file tools, Git, GitHub, MCP, and provider traffic remain host-side. Host-side file tools can still edit the mounted repository, and GitHub or Git operations can still affect remote systems if permissions allow them.
The default sandbox network is host networking. network = "none" provides deny-all networking for sandboxed commands, but yottacode does not provide an in-house egress allowlist. Network controls outside yottacode remain part of the environment’s security architecture.
Credentials are not injected by default. If env_passthrough is configured, selected environment values are made available to sandboxed commands. Treat that as an explicit trust decision, not a convenience setting.
Sandboxing reduces command-execution blast radius. It does not make an unrestricted agent safe to connect to production credentials or production deployment systems.
Traceability is a control, not a reporting afterthought
In a mission-critical environment, the final diff is not enough. An architecture review or incident investigation may need to answer:
- What task and repository context did the agent receive?
- Which model and provider handled the session?
- Which tools ran, with which arguments and targets?
- Which actions were allowed, denied, or approved?
- Which files changed, and which checks ran afterward?
- Did the provider truncate, filter, or interrupt a turn?
The built-in /inspect command provides a read-only session view inside the TUI. It groups assistant turns and exposes prompts, responses, tool calls, arguments, statuses, latency, usage, errors, stop flags, and flagged output. It is useful during development and review because it shows how the agent reached a result rather than only displaying the result.
For durable local records, export a session:
yottacode sessions export <session-id> session.jsonlThe JSONL export contains a session header, user and assistant records, tool calls, tool results, approval metadata, usage, model/provider information, compaction records, and a session summary. It is suitable for local retention, jq queries, diffing, and attaching evidence to an engineering review:
jq 'select(.type == "tool_result" and .status != "ok")' session.jsonl
jq 'select(.type == "tool_call") | [.turn, .tool, .id, .args]' session.jsonlThis is an intentionally local-first audit model. yottacode does not send telemetry to a hosted observability service. If records leave the workstation, the team must define its own redaction, access-control, retention, and secret-handling policy: session exports can contain prompts, paths, command output, tool arguments, and provider metadata.
Traceability also has limits. /inspect is a session inspection view, not an immutable event journal. JSONL exports reconstruct the persisted session history rather than every internal runtime event, and external side effects still require evidence from Git hosting, CI, cloud audit logs, or deployment systems.
A reference architecture for mission-critical work
Use layers rather than one universal “safe mode.” The diagram below is a control model, not a claim that yottacode alone enforces every boundary:
Developer
│
▼
Plan and approval boundary
│
▼
Isolated worktree ── permission policy ── path validation
│ │
▼ ▼
Sandboxed commands Host-side Git/GitHub controls
│ │
└──────────────┬──────────┘
▼
Tests, scanners, and CI
│
▼
Draft pull request
│
▼
Human review and deployment gateEach layer answers a different question:
- Plan: Is this the right change?
- Permissions: Is this action authorized?
- Worktree: Is the change isolated?
- Path validation: Is the target inside the allowed boundary?
- Sandbox: What can the command process reach?
- CI: Does the change satisfy deterministic checks?
- Review: Should this change enter the system?
- Deployment gate: Should this change affect production?
What this architecture does not guarantee
No combination of permissions, worktrees, modes, and sandboxing guarantees that an agent will understand the task correctly or that a human will approve the right action. These are engineering controls, not a promise that production impact is impossible.
Known limitations include:
- A permission policy is not an OS sandbox.
- Podman sandboxing covers selected command execution, not every yottacode tool.
- Host networking is the default sandbox network configuration.
- There is no built-in egress allowlist.
- Resource limits can degrade on hosts that do not support the relevant cgroup or storage features.
- Double-forked or daemonized descendants may outlive command cancellation inside the container.
- External mutations may not be reversible.
- Production repository safety still depends on Git hosting, identity, network, secret, CI, deployment, and external audit-log controls outside yottacode.
These are not reasons to avoid agentic engineering. They are reasons to make the trust boundary explicit before expanding the agent’s authority.
Conclusion
Mission-critical environments need more than a capable model. They need an operating model that limits authority, isolates change, constrains execution, preserves evidence, and keeps production decisions human-owned.
Permissions define what the agent may do. Worktrees contain the change. Modes make autonomy deliberate. Sandboxing constrains selected command execution. CI and review determine whether the result is acceptable. External identity, network, credential, and deployment controls complete the architecture.
The right question is not whether an AI agent can be made perfectly safe. It is whether the system makes its authority narrow enough to understand, its actions visible enough to review, and its failures bounded enough to investigate.
Define the agent’s authority before rollout
Before granting an agent access to a mission-critical repository, document its authority budget and evidence plan: allowed tools, paths, credentials, network access, modes, sandbox profile, required checks, /inspect review, session-export handling, and human approval points. Start with a read-only task, then expand capability one boundary at a time.