MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / buildAgentServerEnv

Function buildAgentServerEnv

scripts/dev-safe.mjs:687–725  ·  view source on GitHub ↗
(config)

Source from the content-addressed store, hash-verified

685 * @returns {Record<string, string>} Environment variables for agent-server
686 */
687export function buildAgentServerEnv(config) {
688 return {
689 // Force Python to use UTF-8 for all file I/O and streams.
690 //
691 // On Windows, Python defaults to the system ANSI codepage (e.g. cp1252).
692 // The agent-server writes conversation metadata JSON that can contain
693 // emoji (e.g. ✅ U+2705) which cp1252 cannot encode, producing:
694 // UnicodeEncodeError: 'charmap' codec can't encode character '\u2705'
695 // Setting PYTHONUTF8=1 enables Python's UTF-8 mode (PEP 540) for the
696 // entire agent-server process, matching the behaviour on Linux/macOS
697 // where the locale is already UTF-8.
698 // This is a no-op on Linux/macOS where the locale is already UTF-8.
699 PYTHONUTF8: "1",
700 TMUX_TMPDIR: config.tmuxTmpDir,
701 // Parent of stateDir (= ~/.openhands) so settings/secrets match Docker.
702 OH_PERSISTENCE_DIR: path.dirname(config.stateDir),
703 OH_CONVERSATIONS_PATH: config.conversationsPath,
704 OH_BASH_EVENTS_DIR: config.bashEventsDir,
705 OH_VSCODE_PORT: String(config.vscodePort),
706 OH_SECRET_KEY: config.secretKey,
707 // Use OH_SESSION_API_KEYS_0 for agent-server V1 config format
708 OH_SESSION_API_KEYS_0: config.sessionApiKey,
709 // Alias for the agent-server's own URL. The agent-server itself sets
710 // OH_INTERNAL_SERVER_URL at startup, but downstream consumers (the
711 // OpenHands SDK boilerplate emitted by automation prompt/plugin
712 // presets) read AGENT_SERVER_URL — the canonical SDK name. Mirror it
713 // here so automation runs work without each tarball having to know
714 // about the OH_-prefixed variant.
715 //
716 // We deliberately do NOT set a SESSION_API_KEY alias: the SDK's
717 // sanitized_env() would strip it from bash subprocesses anyway, and
718 // a follow-up change to the automation preset reads
719 // OH_SESSION_API_KEYS_0 directly (which is already in env).
720 AGENT_SERVER_URL: config.backendBaseUrl,
721 // Let the agent-server resolve canvas_ui_tool when old persisted metadata
722 // requests that compatibility module during startup.
723 OH_EXTRA_PYTHON_PATH: config.canvasToolsDir,
724 };
725}
726
727// Re-export so existing importers (dev-with-automation.mjs, tests) keep
728// resolving `buildRuntimeServicesInfo` from this module. The implementation

Callers 4

startAgentServerFunction · 0.90
mainFunction · 0.90
startAgentServerFunction · 0.90
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected