langchain - 💡(How to fix) Fix Add ClawMoat runtime security integration for AI agents [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36309Fetched 2026-04-08 01:41:02
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
closed ×1commented ×1labeled ×1

Code Example

import { ClawMoat } from 'clawmoat';
import { ClawMoatCallbackHandler } from '@clawmoat/langchain'; // proposed

const moat = new ClawMoat({ policy: 'strict' });

const chain = new AgentExecutor({
  agent,
  tools,
  callbacks: [new ClawMoatCallbackHandler(moat)]
});
RAW_BUFFERClick to expand / collapse

ClawMoat Integration Proposal

ClawMoat is an open-source runtime security layer for AI agents (npm: clawmoat, MIT license, zero dependencies).

What it adds

  • Prompt injection detection (13 attack patterns, session-aware with exponential decay)
  • Jailbreak detection before content reaches the model
  • Secret/credential scanning in agent inputs and outputs
  • Supply chain integrity checking for agent dependencies
  • Network egress logging for agent tool calls

Integration idea

A LangChain callback handler that wraps agent execution with ClawMoat scanning:

import { ClawMoat } from 'clawmoat';
import { ClawMoatCallbackHandler } from '@clawmoat/langchain'; // proposed

const moat = new ClawMoat({ policy: 'strict' });

const chain = new AgentExecutor({
  agent,
  tools,
  callbacks: [new ClawMoatCallbackHandler(moat)]
});

Why now

RSAC 2026 this week showed live exploitation of multiple enterprise AI agents (Cursor, Copilot, Salesforce Agentforce) via prompt injection. LangChain-based agents are widely deployed in production and face the same attack surface.

Happy to build the callback handler integration and submit a PR. Would love feedback on whether this fits the plugin/extension model or should live separately.

cc: anyone on the security working group

Repo: https://github.com/darfaz/clawmoat | Docs: https://clawmoat.com

extent analysis

Fix Plan

To integrate ClawMoat with LangChain, we will create a callback handler that wraps agent execution with ClawMoat scanning. Here are the steps:

  • Install the clawmoat package: npm install clawmoat
  • Create a new file ClawMoatCallbackHandler.js with the following code:
import { ClawMoat } from 'clawmoat';

class ClawMoatCallbackHandler {
  constructor(moat) {
    this.moat = moat;
  }

  async beforeExecute(agent, input) {
    const result = await this.moat.scanInput(input);
    if (result.vulnerable) {
      throw new Error('Prompt injection detected');
    }
  }

  async afterExecute(agent, output) {
    const result = await this.moat.scanOutput(output);
    if (result.vulnerable) {
      throw new Error('Secret/credential scanning detected');
    }
  }
}

export { ClawMoatCallbackHandler };
  • Import the ClawMoatCallbackHandler in your LangChain code and use it as a callback handler:
import { ClawMoat } from 'clawmoat';
import { ClawMoatCallbackHandler } from './ClawMoatCallbackHandler';

const moat = new ClawMoat({ policy: 'strict' });
const callbackHandler = new ClawMoatCallbackHandler(moat);

const chain = new AgentExecutor({
  agent,
  tools,
  callbacks: [callbackHandler]
});

Verification

To verify that the fix worked, you can test the integration by sending a malicious input to the agent and checking if the ClawMoatCallbackHandler detects the prompt injection.

Extra Tips

  • Make sure to configure the ClawMoat instance with the correct policy for your use case.
  • You can customize the ClawMoatCallbackHandler to fit your specific requirements, such as logging or alerting on detected vulnerabilities.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - 💡(How to fix) Fix Add ClawMoat runtime security integration for AI agents [1 comments, 2 participants]