The Drift Log · Governing agents that write code
Restricting Agent Code Generation to Pre-Vetted Internal SDKs
24 November 2026 · 3 min read · 502 words · inference

Restrict agent code generation to audited, model-independent SDK primitives and intercept unverified logic at the build gate.
A pull request lands with 400 lines of pristine TypeScript. The unit tests pass, the variable names make sense, and the reviewer approves it in three minutes. Nobody noticed that the agent solved a rate-limiting problem by inventing its own leaky sliding-window algorithm, adding an unvetted single-purpose utility package, and calling an untracked external helper.
The code passes verification today. Six months later, nobody on the team knows where the logic originated, whether the package has a maintainer, or which concurrency edge cases were missed.
The failure mode of unconstrained agent writes
AI coding agents optimize for local task completion. Given a prompt to implement token management, cryptographic signing, or retry budgets, an agent takes the path of least resistance: it writes raw utility logic from training memory or imports an arbitrary package from an open registry.
Both paths introduce untracked risk:
- Bespoke boilerplate creates silent runtime bugs. Agents frequently write logic that looks idiomatic but fails under subtle edge conditions, such as clock drift, memory leaks in long-running loops, or race conditions in async generators.
- Ad-hoc dependencies create supply-chain debt. When agents pull unvetted libraries to solve trivial subtasks, they expand the dependency graph without security review or license clearance.
Traditional code review automation struggles here. Linters verify syntax; automated reviews evaluate style and test coverage. Neither tells you whether a critical state machine should have been written from scratch by a model in the first place.
// What the agent writes when unconstrained:
// - Imports an unvetted package with untracked transitive dependencies
// - Re-implements critical logic with subtle edge-case gaps
import { tokenBucket } from "unvetted-micro-pkg";
export function handleRequest(req: Request) {
if (!tokenBucket.consume(req.ip)) {
throw new Error("Rate limit exceeded");
}
// ...
}
Enforcing typed SDK boundaries
The solution is not to write longer system prompts instructing the agent to "be careful with dependencies." System instructions degrade as context windows fill.
The reliable control point is structural: restrict the import surface area allowed in agent-authored code. Force the agent to import audited, model-independent primitives from a local, typed SDK rather than synthesising core algorithmic logic from scratch.
// What the agent is constrained to write:
// - Imports from an audited, internal namespace
// - Wires inputs to repeatable, verified contracts
import { TokenBucket } from "@shpbl/sdk";
const limiter = new TokenBucket({ capacity: 100, refillRate: 10 });
export function handleRequest(req: Request) {
if (!limiter.allow(req.ip)) {
return new Response("Too Many Requests", { status: 429 });
}
// ...
}
When an agent is restricted to calling pre-vetted primitives, its role is confined to orchestration: mapping inputs, passing data to audited components, and handling return values. The critical mechanics—state management, parsing, cryptographic guarantees—remain inside reviewed code that no model generated on the fly.
Intercepting the write at the build gate
Restricting imports cannot happen after code merges to your main branch. It must happen before the write touches disk.
Every write an agent performs passes a Build Intent gate first. The tooling registers the proposal, resolves licensing and invariant contracts in code, and returns a terminal state. If the agent needs capability outside its immediate scope, it queries the gate through an MCP server, an HTTP API, or @shpbl/sdk rather than inventing unverified logic.
The gate checks the certification harness for a verdict. Artifacts marked CERTIFIED have executed against strict input contracts; those marked PROVISIONAL are repeatable but pending formal assertion. If an operation violates invariants or introduces untracked dependencies, the gate rejects the write before code review begins.
Previewing the resolution costs nothing; taking the artifact requires entitlement. The boundary holds: agents wire components together, but the shipped software runs on model-independent code sealed by published checksums.
This post supports the longer argument in Placing an Invariant Gate in Front of Coding Agents.
Keep reading
Next in the log
- Placing an Invariant Gate in Front of Coding Agents
Governing coding agents requires replacing raw file-mutation tools with synchronous invariant gates that resolve Build Intent before touching disk.
- Sandboxing MCP Server Tool Calls Against Local Filesystems
OS containers protect user IDs and paths, not code architecture. Staging MCP tool writes behind an in-memory intent gate stops corrupt repo state.
- Evaluating Agent Tool Calls Against Structural Code Invariants
Prevent agent workspace degradation by intercepting file mutation tools with AST-level invariant checks before disk writes occur.
The Strategic Master Library · written and reviewed under the house's own epistemic rules: nothing claimed that we cannot show.