Join our Newsletter — 33% off our NHI Course
Home› Guides› CrewAI security guide: Identity, Tool Hooks, MCP Trust,…
Guide MCP, Protocols & Agent Platforms

CrewAI security guide: Identity, Tool Hooks, MCP Trust, Secrets and Telemetry

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 28 October 2026 12 min read
On this page

A CrewAI crew is a group of agents that call tools, MCP servers and each other with the credentials of the process that runs it, so one over-permissioned tool or one untrusted MCP server can turn a research crew into an unattended actor with production access. CrewAI has changed quickly: its built-in code interpreter has been removed, the agent code execution settings are deprecated, MCP servers can now be attached directly to agents, and tool call hooks give a real enforcement point. This guide covers the four controls that matter most in a CrewAI deployment: the identity and credentials the crew runs with, tool permissions and approval, secrets handling, and telemetry and tracing. It is written for engineers and security reviewers putting CrewAI crews and flows into production. Cross-framework topics, including sandboxing generated code, are in the Securing Agent Frameworks Guide. Facts are from the CrewAI documentation for version 1.15.32 in the project's GitHub repository, checked on 28 October 2026.

Key takeaways

  • A crew has no identity of its own. Every tool authenticates with keys from the environment or its own configuration, so give each crew its own scoped credentials rather than a developer's keys.
  • Use PRE_TOOL_CALL hooks as the policy point. A hook can rewrite tool input or raise HookAborted to block a call, and post-call hooks see every attempt, including blocked ones.
  • Trust decides MCP risk. CrewAI warns that a malicious MCP server can inject instructions through tool metadata simply by being connected and listed, even if no tool is called.
  • Do not put keys in MCP URLs. String references such as a server URL with an api_key query parameter put the secret in logs and traces; use structured configurations with headers.
  • Decide telemetry and tracing deliberately. Anonymous telemetry is on by default, share_crew sends task descriptions and backstories, and AMP tracing is controlled separately by CREWAI_TRACING_ENABLED.

Where CrewAI's security boundaries are

CrewAI organises work as agents (a role, goal, backstory, LLM and tools), tasks (work with an expected output, optional guardrails and optional human input), crews (agents and tasks run sequentially or hierarchically) and flows (event-driven orchestration with state). All of them run inside your Python process. The boundaries you control are:

BoundaryCrewAI mechanismWhat can go wrongControl
Model accessllm on each agent, keys from environment variablesShared or personal provider keys, cost abuseOne scoped key per crew and environment, spend limits at the provider
Toolstools on agents or tasks, custom BaseTool classesTool reaches more than the task needsPer-task tool lists, least-privilege credentials, hooks
MCP serversmcps field, MCPServerStdio, MCPServerHTTP, MCPServerSSE, or MCPServerAdapterMalicious server, metadata injection, local command executionTrusted servers only, tool_filter, pinned packages
Delegationallow_delegation (default False)An agent hands work to one with stronger toolsLeave off unless the crew design needs it
Code executionallow_code_execution, code_execution_mode (deprecated); CodeInterpreterTool removedGenerated code runs on the hostExternal sandbox service; see the sandboxing guide
Memory and knowledgeUnified Memory with hierarchical scopes, knowledge_sourcesOne agent reads another's private contextScoped views per agent (for example memory.scope("/agent/researcher"))
Telemetry and tracingCREWAI_DISABLE_TELEMETRY, share_crew, CREWAI_TRACING_ENABLEDTask content leaves the organisationExplicit settings per environment

Identity and credentials

CrewAI's examples set provider and tool keys as environment variables (for instance OPENAI_API_KEY and SERPER_API_KEY), which is fine for a laptop and a problem in production if every crew shares the same keys. Treat each deployed crew as a non-human identity with its own credentials. See the Non-Human Identity (NHI) Guide.

  • Per-crew keys: issue separate model and tool keys for each crew and environment, so usage, cost and revocation map to one crew. A shared key makes a leak a whole-estate incident.
  • Workload identity where the tool supports it: custom tools that call cloud APIs should use the platform's workload identity (managed identity, IAM role, service account federation) instead of a stored key. See the Workload Identity Federation Guide.
  • Scope tool credentials to the task: a research crew's search tool needs a search API key, not a GitHub token. Where one tool needs write access, give it to a dedicated agent with that tool alone.
  • Least privilege for MCP credentials: CrewAI's MCP guidance says credentials used by MCPServerAdapter should have only the permissions the required tools need.
  • Keep humans' keys out: a crew running on an engineer's personal token outlives the engineer's role and blurs audit trails.

The cost of one over-privileged token is clear from the CrewAI "Uncrew" Flaw 2025: a failed provisioning status check on CrewAI's own platform returned an error payload containing a GitHub token that the researchers said had administrative privileges across CrewAI's GitHub organisation. CrewAI fixed it within hours; the lessons are to redact secrets from errors and to scope tokens narrowly.

Tool permissions, hooks and human approval

CrewAI's tool call hooks run at two interception points: PRE_TOOL_CALL before every tool execution and POST_TOOL_CALL after it. Register them with the @on decorator (the older @before_tool_call and @after_tool_call decorators still work and share the same chain).

NeedMechanismNotes
Block a callRaise HookAborted in a PRE_TOOL_CALL hookThe tool does not run; the agent receives "Tool execution blocked by hook" and the run continues
Validate or sanitise inputMutate ctx.tool_input in placeReplacing the dictionary instead of editing it means the tool never sees the change
Human approval for a toolctx.request_human_input(prompt, default_message) in a pre-call hookConsole-based; for services, route approvals to your own queue
Redact outputReturn a replacement string from a POST_TOOL_CALL hookraw_tool_result keeps the original object
Audit every attemptPOST_TOOL_CALL hook logging tool_name, agent, taskFires on blocked calls too
Review a task's final answerhuman_input=True on the taskReviews output, not individual tool calls
Validate output before the next taskguardrail or guardrails, guardrail_max_retries (default 3)Use for format and policy checks on what flows between agents
  • Allowlist, do not denylist: a pre-call hook that permits named tools with argument checks for each is far stronger than one that searches for bad strings.
  • Bound autonomy: max_iter (default 20), max_execution_time, max_rpm and max_retry_limit (default 2) cap runaway loops and cost. Set them explicitly for production agents.
  • Keep delegation off by default: with allow_delegation=True an agent can hand work to another agent, which may hold stronger tools. Enable it only where the crew design needs it and check the delegate's tools.
  • Tool caching: tool results are cached by default (cache=True). Use cache_function or turn caching off for tools whose results are user-specific or sensitive.

See the OWASP LLM Top 10 LLM06 Excessive Agency Guide and the AI Agent Tool and Plugin Security Guide.

MCP servers in CrewAI

CrewAI's MCP security page opens with one rule: only connect agents to MCP servers you fully trust. It lists the risks as arbitrary code execution (especially over stdio), data exposure, unintended API calls and prompt injection, and calls out injection through tool metadata as the subtle one: names and descriptions enter the model's context as soon as tools are listed.

  • Filter tools: use create_static_tool_filter(allowed_tool_names=[...]) or the server#tool string syntax so the agent sees only the tools it needs. Fewer listed tools also means less untrusted metadata in context.
  • Pin stdio servers: MCPServerStdio(command="npx", args=["-y", ...]) fetches and runs a package with the agent's operating system rights. Pin versions and run the process with minimal file system access.
  • Remote servers over HTTPS with headers: use MCPServerHTTP with credentials in headers. Avoid string references that carry ?api_key= in the URL.
  • Local development servers: CrewAI advises binding them to 127.0.0.1, validating Origin and Host headers and requiring authentication, as defences against DNS rebinding.
  • Watch OAuth behaviour: CrewAI describes confused deputy and token passthrough risks in MCP proxies; be cautious when a server triggers unexpected or broad OAuth consent.
  • Connected integrations by slug: references such as "github" or "stripe#list_invoices" use integrations connected in your CrewAI account; review which account connections exist and what scopes they hold.

See the MCP Security Guide.

Secrets handling

  • Load from a secret store at start-up: inject provider and tool keys from your platform's secret manager into the process environment; do not commit .env files or bake them into images.
  • Do not put secrets in roles, goals, backstories or task text: these flow into prompts, traces and, with share_crew, to CrewAI.
  • Return minimal tool output: a tool that returns a raw API response can hand the model a token. A POST_TOOL_CALL hook can redact before the agent sees the result.
  • Return generic errors: the Uncrew flaw was a detailed error carrying a credential. Catch exceptions in custom tools and log detail internally only.
  • Stdio env maps: the env={"API_KEY": ...} parameter on MCPServerStdio should read from your secret store, never a literal.

See the API Key Management Guide.

Telemetry, tracing and logging

SettingDefaultEffectProduction choice
Anonymous telemetryOnVersions, crew and agent metadata, role names, tool names, LLM attributes, exception class names (not messages)Disable with CREWAI_DISABLE_TELEMETRY=true if policy forbids any outbound telemetry
share_crewOffAdds goals, backstories, task descriptions, expected outputs and inputs; CrewAI warns this may include personal dataKeep off
OTEL_SDK_DISABLED=trueUnsetDisables CrewAI's exporter and all OpenTelemetry in the processUse only if you do not need your own tracing
AMP tracingOpt-in; a first run may prompt "Share this execution trace with CrewAI? [y/N]"tracing=True or CREWAI_TRACING_ENABLED=true sends agent decisions, tool usage and LLM calls to the CrewAI AMP platformEnable only if AMP is an approved processor; OTEL_SDK_DISABLED does not turn it off

CrewAI's own telemetry runs on a private TracerProvider, so it neither receives your application spans nor appears in your back end. For your own audit trail, use an observability integration or a POST_TOOL_CALL hook that logs tool name, agent role, task, outcome and whether it was blocked, and send those events to your SIEM. Do not put personal data in agent roles or tool names, since CrewAI collects them by default.

Metrics: crews running on shared or personal keys (target zero); tools covered by pre-call allowlist hooks; blocked tool calls per week; MCP servers with unpinned versions; environments with share_crew or AMP tracing on without approval; agents with delegation enabled.

Rollout approach

  1. Inventory: list crews and flows, their LLM keys, tools, MCP servers, delegation and code execution settings, and telemetry and tracing choices.
  2. Remove deprecated execution: replace allow_code_execution and any remaining CodeInterpreterTool use with an external sandbox.
  3. Add hooks in log-only mode: register a POST_TOOL_CALL logging hook and a PRE_TOOL_CALL hook that records would-be blocks without raising. Run for a week in staging.
  4. Enforce: switch the pre-call hook to raise HookAborted for calls outside the allowlist. Roll back by returning the hook to log-only.
  5. Split credentials: move each crew to its own keys and tool identities, then revoke the shared ones.
  6. Fix telemetry settings: set telemetry, share_crew and tracing explicitly per environment in deployment configuration, not in code defaults.

Common failure patterns

  • Connecting MCP servers from a directory listing: metadata injection works on connection alone.
  • One "god" agent: every tool on one agent with delegation on, so any prompt injection reaches everything.
  • Keys in MCP URLs and literal env values: they leak through logs, traces and repositories.
  • Verbose errors from custom tools: stack traces and request objects carrying credentials, the Uncrew pattern.
  • Tracing turned on by an environment variable nobody owns: CREWAI_TRACING_ENABLED=true in a shared .env enables it for every crew.

Framework mapping

RiskCrewAI controlReference
Excessive agencyPer-task tools, pre-call hooks, delegation off, iteration limitsOWASP LLM06:2025 Excessive Agency; NIST SP 800-53 AC-6
Prompt injection via MCP metadata or tool outputTrusted servers, tool filters, guardrailsOWASP LLM01:2025 Prompt Injection
Secrets in errors, traces and telemetryGeneric errors, redaction hooks, share_crew offOWASP LLM02:2025 Sensitive Information Disclosure
Unpinned tools and serversPinned packages and MCP serversOWASP LLM03:2025 Supply Chain
Shared credentialsPer-crew keys, workload identityNIST CSF 2.0 PR.AA-01; SP 800-53 IA-5
Audit trailPost-call logging hook to SIEMSP 800-53 AU-2; CSF DE.CM-03

Practitioner checklist

  • Give every production crew its own model and tool credentials, sourced from a secret store.
  • Attach tools per task and agent; keep allow_delegation off unless designed in.
  • Enforce a PRE_TOOL_CALL allowlist hook and log every attempt with POST_TOOL_CALL.
  • Connect only trusted MCP servers, filter their tools and pin stdio packages.
  • Move all credentials out of MCP URLs and literal env values.
  • Replace deprecated code execution settings with an external sandbox.
  • Set telemetry, share_crew and AMP tracing explicitly per environment.
  • Set max_iter, max_execution_time and max_rpm for every production agent.

Standards and references

Related NHI Mgmt Group resources: Securing Agent Frameworks Guide, LangChain and LangGraph Security Guide, MCP Security Guide, AI Agent Sandboxing and Code Execution Guide, CrewAI "Uncrew" Flaw 2025.

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 28 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.