MCPcopy Create free account
hub / github.com/langchain-ai/deepagents / _build_server_env

Function _build_server_env

libs/code/deepagents_code/server.py:323–356  ·  view source on GitHub ↗

Build the environment dict for the server subprocess. Copies `os.environ`, sets required flags, and strips variables that are not needed or can alter subprocess startup behavior. A launch-time `PYTHONPATH` is captured into `config._INHERITED_PYTHONPATH_ENV` before being stripped, s

()

Source from the content-addressed store, hash-verified

321
322
323def _build_server_env() -> dict[str, str]:
324 """Build the environment dict for the server subprocess.
325
326 Copies `os.environ`, sets required flags, and strips variables that are not
327 needed or can alter subprocess startup behavior.
328
329 A launch-time `PYTHONPATH` is captured into `config._INHERITED_PYTHONPATH_ENV`
330 before being stripped, so the value never reaches the server interpreter's
331 `sys.path` but can still be re-applied to agent `execute` commands downstream.
332
333 Returns:
334 Environment dict for `subprocess.Popen`.
335 """
336 env = os.environ.copy()
337 env["PYTHONDONTWRITEBYTECODE"] = "1"
338 env["LANGGRAPH_AUTH_TYPE"] = "noop"
339
340 # Capture a launch-time PYTHONPATH before stripping it. Never trust an
341 # inherited carrier var: pop it first, then set it only from the real value.
342 env.pop(_INHERITED_PYTHONPATH_ENV, None)
343 inherited_pythonpath = os.environ.get("PYTHONPATH")
344
345 for key in (
346 "LANGGRAPH_AUTH",
347 "LANGGRAPH_CLOUD_LICENSE_KEY",
348 "LANGSMITH_CONTROL_PLANE_API_KEY",
349 "LANGSMITH_TENANT_ID",
350 *_SERVER_ENV_DENYLIST,
351 ):
352 env.pop(key, None)
353
354 if inherited_pythonpath is not None:
355 env[_INHERITED_PYTHONPATH_ENV] = inherited_pythonpath
356 return env
357
358
359# ---------------------------------------------------------------------------

Calls 1

getMethod · 0.45