Integration: Custom agents
How do I secure a custom coding agent built on an agent SDK?
Updated
Short answer
Put a check in front of every tool call your harness makes, run it outside the agent, and make it fail closed. Agent SDKs give you the hook points, such as PreToolUse in the Claude Agent SDK and tool guardrails in the OpenAI Agents SDK, but you write the check, and some tools skip those paths. Harden AIF is a ready-made check on the developer's machine that your harness calls before each action runs.
What a custom coding agent can do#
A harness you build on an agent SDK gets whatever tools you hand it: a shell, file edits, an HTTP client, MCP servers, your internal APIs. It runs with the credentials of the machine or service account it lives on. One injected instruction in a ticket, a doc or a tool result, and it uses those tools against you.
What the SDKs give you, and what they leave to you#
- Claude Agent SDK hooks. A PreToolUse callback runs when a tool is about to be called and can allow it, block it or change its input. Hooks run first, and a hook deny applies even in
bypassPermissionsmode. But you write the logic, and a narrow matcher leaves holes: the docs' own example is a guard on file writes where, if Claude writes.envwith a Bash command, "the hook doesn't run". - Claude Agent SDK `canUseTool`. It only runs if nothing earlier decided. The permissions docs warn that checks there are "silently bypassed" for auto-approved tools.
- OpenAI Agents SDK tool guardrails. Input tool guardrails "run before the tool executes" and can skip the call. Hosted tools and built-in execution tools "do not use this guardrail pipeline", per the guardrails docs.
- Human approvals.
needs_approvalpauses a run until someone approves. That works for a handful of risky calls, and turns into rubber-stamping at volume.
So the SDK hands you the hook. What you still need is the check behind it, one that reads the real command, holds up when the command is obfuscated, and doesn't fail open when it crashes.
What Harden AIF checks before each action#
AIF is a separate service on the developer's machine. Your harness calls it through the same pre-tool point before each action runs, so the check sits outside the agent and its context window. For each pending action, it:
- parses the command into a syntax tree and follows each value from its source to where it ends up, so a secret headed for a network call gets blocked however the command is written;
- judges secrets by their content, not their file name;
- checks destructive commands (recursive deletes, force-pushes to the default branch, piping
curlinto a shell, disk wipes) against where they actually run; - decodes base64 and hex before it decides, and sends dynamic code it can't resolve to a human;
- fails closed: if the check can't run, the action doesn't run.
When it blocks, the agent gets the reason and can retry a safe way. Every decision is recorded, and you can export the records to your SIEM.
How to set up Harden for a custom agent#
- Install AIF with
curl -fsSL https://aif.harden.run/install.sh | sh, then open a new shell. - Run
aif status, andaif doctorif anything isn't ready. - If your harness sends tools through an MCP server, the CLI reference lists
aif mcp-proxyto protect actions sent that way. - Talk to a Harden engineer to wire your harness's pre-tool hook to AIF and validate the first protected run.
FAQ
Questions about Custom agents
Where should a custom agent check actions?
At the last point before the tool runs, with the real arguments in hand: PreToolUse in the Claude Agent SDK, or a tool input guardrail in the OpenAI Agents SDK. Earlier checks on the prompt can't see what the agent finally decides to run.
Are input and output guardrails enough for a coding agent?
No. In the OpenAI Agents SDK, input guardrails run only for the first agent in a chain and output guardrails only for the agent that produces the final output. A coding agent needs a check on each tool call.
Does Harden work with harnesses we built ourselves?
Yes. Harden AIF works with custom harnesses as well as Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot and Kiro. Your harness calls the local service before each action, and Harden's engineers help you wire it up.