# How we add runtime security to LangChain agents in production

**URL:** <https://forum.langchain.com/t/how-we-add-runtime-security-to-langchain-agents-in-production/3461>\
**Category:** Talking Shop\
**Created:** [April 20, 2026, 1:09pm UTC](https://forum.langchain.com/t/how-we-add-runtime-security-to-langchain-agents-in-production/3461 "2026-04-20T13:09:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![samueloladji-beep](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/samueloladji-beep/32/2862_2.png) [@samueloladji-beep](https://forum.langchain.com/u/samueloladji-beep)\
**Post date:** [April 20, 2026, 1:09pm UTC](https://forum.langchain.com/t/how-we-add-runtime-security-to-langchain-agents-in-production/3461/1 "2026-04-20T13:09:43Z")

</div>

Been seeing a lot of questions about production safety for LangChain agents so wanted to share what we use.

The problem: once a LangChain agent has tool access in production, there’s no built-in way to intercept and block dangerous actions before they execute.

Here’s a lightweight approach using Vaultak:

```python
pip install vaultak

from vaultak import Vaultak

vt = Vaultak(api_key="vtk_...")

with vt.monitor("my-agent"):
    result = agent.invoke({"input": user_input})

```

Every tool call now gets risk-scored before execution. You can add policies to block specific actions:

```python
vt.policy.create({
    "name": "no-prod-deletes",
    "action": "delete",
    "resource": "production_*",
    "effect": "deny",
    "priority": 1
})

```

There’s also a free scanner at [AI Agent Risk Scanner, Vaultak](http://vaultak.com/scan) if you want to check your agent’s risk profile without writing any code first.

Full guide with more examples:

> **[How to Secure LangChain Agents in Production](https://vaultak.com/blog/how-to-secure-langchain-agents)**
>
> A practical guide to adding runtime security to LangChain agents.

Happy to answer questions about the implementation.

---

<div class="post-metadata">

**Author:** ![keenborder786](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/keenborder786/32/1757_2.png) [@keenborder786](https://forum.langchain.com/u/keenborder786)\
**Post date:** [April 20, 2026, 2:33pm UTC](https://forum.langchain.com/t/how-we-add-runtime-security-to-langchain-agents-in-production/3461/2 "2026-04-20T14:33:27Z")

</div>

@samueloladji-beep , why not wrap this in a [middleware](https://docs.langchain.com/oss/python/langchain/middleware/overview), rather than using it in a context manager.

---

<div class="post-metadata">

**Author:** ![samueloladji-beep](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/samueloladji-beep/32/2862_2.png) [@samueloladji-beep](https://forum.langchain.com/u/samueloladji-beep)\
**Post date:** [April 20, 2026, 4:10pm UTC](https://forum.langchain.com/t/how-we-add-runtime-security-to-langchain-agents-in-production/3461/3 "2026-04-20T16:10:56Z")

</div>

middleware is actually cleaner for production use. Here’s how you’d do it:

from langchain.callbacks.base import BaseCallbackHandler  
from vaultak import Vaultak

class VaultakHandler(BaseCallbackHandler):  
def **init** (self, api\_key: str, agent\_name: str):  
self.vt = Vaultak(api\_key=api\_key)  
self.agent\_name = agent\_name

```auto
def on_tool_start(self, tool, input_str, **kwargs):
    self.vt.log_action(
        agent_id=self.agent_name,
        action_type="tool_call",
        resource=tool["name"],
        payload=input_str
    )

```

agent.invoke(  
{“input”: user\_input},  
config={“callbacks”: [VaultakHandler(api\_key=“vtk\_…”, agent\_name=“my-agent”)]}  
)

The context manager approach is simpler for quick setup. The callback handler is better for production; it hooks directly into LangChain’s execution lifecycle so you get per-tool visibility rather than wrapping the whole invocation.  
We’re actually adding a native LangChain integration to the SDK. Will post here when it’s ready.
