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

Function buildAgentServerEnv

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

Source from the content-addressed store, hash-verified

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