Join our Newsletter — 33% off our NHI Course
Home› Guides› LangChain and LangGraph Security Guide: Credentials, Agent Server…
Guide AI Platforms

LangChain and LangGraph Security Guide: Credentials, Agent Server Auth and LangSmith

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 8 November 2026 14 min read
On this page

LangChain and LangGraph applications hold every credential their agents use, and when deployed on the LangGraph Agent Server or traced to LangSmith they add their own API keys, workspaces and authorisation layer that teams often leave at defaults. LangChain's own security policy tells developers to assume any credential an LLM application holds may be used in any way its permissions allow. This guide turns that into concrete controls for the LangChain stack: the credentials inside the application, Agent Server authentication and resource authorisation, LangSmith organisation roles and key types, trace data exposure, and the serialisation flaws that have turned stored data into secret disclosure. The cross-framework view (CrewAI, AutoGen and others, code execution settings, multi-agent delegation) is in the Securing Agent Frameworks Guide and is not repeated here. It is written for application security engineers, platform teams and developers running LangChain or LangGraph in production. Details are from LangChain documentation and GitHub advisories checked 27 October 2026.

This is an independent guide from NHI Mgmt Group, based on LangChain's public documentation as of November 2026. It is not sponsored or reviewed by LangChain. Product features change, so confirm settings against LangChain's current documentation.

Key takeaways

  • The framework has no identity of its own. A LangChain agent acts with whatever API keys, database credentials and OAuth tokens the application process holds, so scoping those credentials is the primary control.
  • Self-hosted Agent Server has no default authentication. On LangSmith deployments the default is a LangSmith API key in x-api-key; self-hosted servers are open until you implement @auth.authenticate.
  • Authorisation is yours to write. Without @auth.on handlers that tag resources with an owner and return filters, any authenticated caller can read every thread, assistant, cron and store item.
  • Use service keys, not personal tokens. LangSmith Personal Access Tokens (lsv2_pt_) carry a user's permissions and die when the user leaves; service keys (lsv2_sk_) and tracing keys (lsv2_tr_) are built for applications, and no key expires unless you set an expiry.
  • Serialised data can carry secrets out. Keep langchain-core on a current release (0.3.81 or 1.2.5 and later), keep secrets_from_env off and treat stored objects as untrusted input.

How identity and access work in LangChain and LangGraph

There are three identity planes in a typical deployment, and each has a different owner.

PlaneWho authenticatesMechanismDefault
Application to tools and modelsThe agent process to model providers, databases, SaaS APIs and MCP serversCredentials loaded by the application: environment variables, secrets managers, OAuth tokens passed in run contextWhatever the developer configured, often broad shared keys
Client to Agent ServerEnd users or front-end applications calling a LangGraph deploymentLangSmith API key (x-api-key) on LangSmith deployments, or custom auth via the Auth objectLangSmith key on LangSmith; none when self-hosted
People and services to LangSmithDevelopers, operators and tracing clientsOrganisation and workspace roles; PATs, service keys, tracing keys; SSO at organisation levelDeveloper organisations make every user Organization Admin; RBAC is Enterprise-only
  • User-scoped credentials: values returned from @auth.authenticate are added to the run context (available in the app as config["configuration"]["langgraph_auth_user"]), so an agent can call MCP servers, databases or other agents with the end user's credentials rather than a shared service credential. This is the pattern to prefer whenever the downstream system can enforce per-user access.
  • LangChain's three principles: limit permissions (read-only credentials, blocked sensitive resources, sandboxing such as containers, proxies), anticipate misuse (a credential that allows deletion should be treated as if it will be used to delete), and defence in depth (combine read-only permissions with sandboxing rather than relying on one safeguard).

For the credential side in depth, see the Credential Vaulting for AI Agents Guide.

Admin roles and privileged access

LangSmith organisation and workspace roles

RoleScopeCan doNotes
Organization AdminOrganisationBilling, workspaces, users, custom roles; Admin on every workspaceDefault for every user in Developer organisations
Organization UserOrganisationRead-only at organisation level; can create PATsPlus and Enterprise plans
Organization ViewerOrganisationAs Organization User but cannot create PATsSelf-hosted needs Helm chart 0.11.25 or later
Workspace AdminWorkspaceFull access, including users, roles and service keysTreat as privileged
Workspace EditorWorkspaceEverything except workspace managementTypical developer role
Workspace ViewerWorkspaceRead-onlyReviewers, support
  • RBAC depends on plan: LangSmith documents workspace RBAC and custom workspace roles as Enterprise-only; on other plans all users get the Admin role. If you are not on a plan with RBAC, the only isolation is between workspaces, so put production tracing and deployments in a workspace with very few members.
  • Workspaces are the trust boundary: LangSmith recommends one workspace per team. Separate production from development workspaces so that developers can experiment without reading production traces.
  • Prefer Organization Viewer for people who should not mint tokens, because Organization User can create PATs that carry their permissions into scripts.

Agent Server operators

Whoever can deploy a graph or edit langgraph.json controls the authentication handler path, whether auth.allow_langsmith_api_keys is enabled alongside custom auth, and which environment variables (and therefore secrets) the server receives. Gate deployment through CI with review, and keep that configuration in version control.

Integrations, API tokens and service accounts

LangSmith key types

KeyPrefixBound toUse forLifecycle
Personal Access Tokenlsv2_pt_A user and that user's permissionsIndividual developer tooling only; not recommended for applicationsStops working when the user leaves; can be deactivated and reactivated
Service keylsv2_sk_A service account, scoped to one, several or all workspacesApplications, CI, deployments; target a workspace with X-Tenant-IdCreated by admins; can be deleted but not deactivated
Tracing keylsv2_tr_The organisation, fixed permissions to submit traces and create projectsApplications that only send tracesCannot read traces or administer; survives creator leaving
Legacy keyls__-NoneNo longer supported
  • Least privilege for tracing: an application that only emits traces should hold a tracing key, which cannot read stored traces. A leaked service key with all-workspace scope exposes every trace and prompt in the organisation.
  • Set expiry: expiration dates are optional and keys never expire by default. Set one on every key and rotate before it lapses; expired keys cannot be reactivated.
  • Storage: keep LANGSMITH_API_KEY and model provider keys in a secrets manager injected at runtime, not in notebooks, .env files committed to repositories or container images. See the LLMjacking Guide.

Agent Server authentication and authorisation

  1. Authenticate every request: implement @auth.authenticate to validate a bearer token from your IdP (signature, issuer, audience, expiry) and return a user dict with identity and, where useful, permissions, role or org_id. Raise Auth.exceptions.HTTPException with 401 on failure.
  2. Authorise by resource: add @auth.on handlers. The single-owner pattern sets value["metadata"]["owner"] on create and returns {"owner": ctx.user.identity} as a filter on read and search. The most specific handler wins: global @auth.on, then resource (@auth.on.threads, .assistants, .crons), then action (@auth.on.threads.create_run).
  3. Scope the store: store handlers work differently: they rewrite the namespace in value to scope long-term memory per user rather than returning filters. Without this, one user's stored memories are readable by others.
  4. Check permissions for writes: use the permission pattern (for example threads:write) for actions such as create_run, because runs inherit access from their parent thread.
  5. Decide on LangSmith keys: enabling auth.allow_langsmith_api_keys lets API keys work alongside custom auth. Anyone holding a workspace key then bypasses your user model, so enable it only for operator access and log it.

Tools, MCP and model providers

  • Per-tool credentials: give each tool its own credential with the narrowest scope: read-only database users limited to required tables (as LangChain's policy suggests), API keys restricted to endpoints, file access limited to one directory.
  • MCP: the newer langchain.mcp MCPAdapter (beta, langchain[mcp] 1.4.0 or later) connects over Streamable HTTP for URLs or launches a subprocess over stdio for a script path; it rejects strings that are not URL-shaped, because a string naming an existing script would otherwise launch as a subprocess. Treat stdio server definitions as code execution and remote servers as third parties. See the MCP Security Guide.
  • Delegated calls: pass end-user tokens from langgraph_auth_user to downstream services that enforce per-user access, rather than one service credential that sees everything. See the OAuth Token Exchange and Delegation Guide.

Serialisation and the secrets it can leak

LangChain persists objects through dumps(), dumpd(), load() and loads(), and LangGraph persists checkpoints. LangChain publishes security fixes under its security policy; apply security updates promptly, and treat any stored framework object as untrusted input unless only your code could have written it.

AreaPackage and versionsEffectFix and hardening
Object serialisationlangchain-core < 0.3.81 and >= 1.0.0, < 1.2.5Serialised dictionaries with 'lc' keys can be revived as LangChain objects on load(), so secrets_from_env=True could expose environment variablesUpgrade to 0.3.81 or 1.2.5; keep secrets_from_env=False; set allowed_objects to an explicit list; leave init_validator at its default, which blocks Jinja2 templates; review astream_events(version="v1") and Runnable.astream_log()
Checkpoint serialisation (see the Securing Agent Frameworks Guide)LangGraph checkpoint packages before 3.0.0Code execution when deserialising checkpoint payloads in the JSON fallback modeUpgrade; protect the checkpointer database with its own credentials, encryption and network limits
  • Where user data hides: fields such as additional_kwargs, response_metadata and metadata can carry user-controlled content into serialised output. Model output counts as user-controlled when the model has read untrusted content.
  • Identity angle: deserialisation issues can reach only the secrets present in the process environment. Workload identity and short-lived tokens shrink what any such flaw can reach. See the Insecure Deserialisation Guide.

Logging and detection

  • Traces are sensitive data: LangSmith traces contain prompts, retrieved documents, tool inputs and outputs. Masking runs client-side before data leaves the application: LANGSMITH_HIDE_INPUTS=true, LANGSMITH_HIDE_OUTPUTS=true and LANGSMITH_HIDE_METADATA=true hide everything; hide_inputs and hide_outputs functions, an anonymizer from create_anonymizer, or process_inputs on @traceable redact selectively. Use conditional tracing for requests that must never be traced.
  • Retention: base trace retention is 14 days; LangSmith states that from 14 September 2026 the maximum extended retention for SaaS is 180 days. Deletion by trace ID or metadata runs on weekends without confirmation, so re-query to verify.
  • Server-side logs: log every @auth.authenticate failure and every 403 from @auth.on handlers with identity and resource; these are the signals for enumeration of other users' threads.
  • Credential use: watch model provider usage per key for spikes and new source networks, and cloud or database audit logs for the agent's credentials touching new resources.
SignalSourceWhy it matters
Repeated 403s on threads or store for one identityAgent Server auth handler logsAttempts to read other users' state
LangSmith key used from an unknown network or after its owner leftLangSmith admin views, network logsLeaked or orphaned key
Model provider spend jump for one keyProvider billing and usage APIsKey theft or agent loop
Agent database user issuing writes or DDLDatabase audit logsPrompt-driven misuse of an over-scoped credential
Unexpected load() of objects outside the allowed listApplication logs around deserialisationSerialisation injection attempts

Metrics: share of deployments with custom auth and owner filters on all resources; applications using PATs instead of service or tracing keys (target zero); keys without expiry; langchain-core and checkpoint package versions below the fixed releases; tools whose credentials are read-only; traces sent without masking where data classification requires it.

Hardening baseline

  1. Inventory: list every LangChain or LangGraph application, its deployment target (LangSmith, self-hosted Agent Server, embedded), the credentials it loads and the LangSmith keys it uses.
  2. Patch and pin: upgrade langchain-core to 0.3.81, 1.2.5 or later and LangGraph checkpoint packages to 3.0.0 or later; pin versions in a lock file and scan dependencies in CI.
  3. Authenticate the server: implement @auth.authenticate against your IdP on every self-hosted Agent Server before exposing it beyond localhost; on LangSmith deployments, replace shared API keys with custom auth for end-user traffic.
  4. Authorise resources: add owner metadata and filters for threads, assistants and crons, and namespace scoping for the store. Test with two users who try to read each other's threads; both must get 403 or empty results.
  5. Re-key LangSmith: move applications from PATs to tracing keys (trace-only) or workspace-scoped service keys, set expiry on all keys, and remove legacy keys.
  6. Scope tool credentials: read-only, table- or endpoint-limited credentials per tool, from a secrets manager; containers or sandboxes for file and code tools.
  7. Mask and retain deliberately: configure hiding or anonymisation for traces that carry personal or secret data, and set retention to policy.
  8. Roll out safely: introduce new auth handlers behind a feature flag or on a staging deployment, replay recorded traffic, then switch; rollback is reverting the langgraph.json auth path through the same reviewed pipeline.

Common misconfigurations

  • Self-hosted server with no auth: a LangGraph server deployed for a demo is reachable on the network and lets anyone create runs that use the server's credentials.
  • Authentication without authorisation: custom auth is in place but no @auth.on handlers, so every signed-in user can list and read every thread.
  • Developer PAT in production: the application traces with a personal token that has Admin rights and stops working, or keeps working, depending on what happens to the developer.
  • One all-workspace service key everywhere: the same key sits in development laptops, CI and production, so a leak anywhere exposes production traces.
  • Agent with an admin database user: the SQL tool connects with an owner account because "read-only broke a query", against LangChain's own advice to scope database credentials to the tables needed.
  • Unmasked traces of regulated data: retrieved customer records and tool outputs are stored in LangSmith for months without anyone deciding that they should be.
  • Old langchain-core through a transitive dependency: the application pins a recent LangChain but another package pulls an unpatched core version.

Framework mapping

AreaNIST SP 800-53 Rev. 5NIST CSF 2.0OWASP
Agent Server authentication and resource filtersIA-2, AC-3 Access EnforcementPR.AA-05API1:2023 Broken Object Level Authorization
Tool credential scopingAC-6 Least Privilege, IA-5 Authenticator ManagementPR.AA-01LLM06 Excessive Agency
Serialisation flaws and patchingSI-2 Flaw Remediation-LLM03 Supply Chain
Trace masking and retentionAU-2 Event Logging, SI-12 Information Management and RetentionDE.CM-03LLM02 Sensitive Information Disclosure

Practitioner checklist

  • Upgrade langchain-core to 0.3.81 or 1.2.5 or later and LangGraph checkpoint packages to 3.0.0 or later, checking transitive versions.
  • Never load() or loads() untrusted data; set allowed_objects explicitly and keep secrets_from_env off.
  • Implement @auth.authenticate on every Agent Server, especially self-hosted ones.
  • Add owner metadata and filters with @auth.on for threads, assistants and crons, and namespace scoping for the store.
  • Replace PATs in applications with tracing keys or workspace-scoped service keys, all with expiry.
  • Separate production and development LangSmith workspaces and keep Admin roles to a few people.
  • Give each tool its own narrowly scoped credential from a secrets manager.
  • Pass end-user credentials through run context where downstream systems enforce per-user access.
  • Mask sensitive trace content client-side and set retention to policy.

Standards and references

Related NHI Mgmt Group resources: Securing Agent Frameworks Guide · Credential Vaulting for AI Agents Guide · MCP Security Guide · AI Agent Memory Security Guide

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 8 November 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.