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

Function buildAgentServerEnv

scripts/dev-safe.mjs:742–781  ·  view source on GitHub ↗
(config, env = process.env)

Source from the content-addressed store, hash-verified

740}
741
742export function buildAgentServerEnv(config, env = process.env) {
743 return {
744 ...buildAgentServerTelemetryEnv(env),
745 // Force Python to use UTF-8 for all file I/O and streams.
746 //
747 // On Windows, Python defaults to the system ANSI codepage (e.g. cp1252).
748 // The agent-server writes conversation metadata JSON that can contain
749 // emoji (e.g. ✅ U+2705) which cp1252 cannot encode, producing:
750 // UnicodeEncodeError: 'charmap' codec can't encode character '\u2705'
751 // Setting PYTHONUTF8=1 enables Python's UTF-8 mode (PEP 540) for the
752 // entire agent-server process, matching the behaviour on Linux/macOS
753 // where the locale is already UTF-8.
754 // This is a no-op on Linux/macOS where the locale is already UTF-8.
755 PYTHONUTF8: "1",
756 TMUX_TMPDIR: config.tmuxTmpDir,
757 // Parent of stateDir (= ~/.openhands) so settings/secrets match Docker.
758 OH_PERSISTENCE_DIR: path.dirname(config.stateDir),
759 OH_CONVERSATIONS_PATH: config.conversationsPath,
760 OH_BASH_EVENTS_DIR: config.bashEventsDir,
761 OH_VSCODE_PORT: String(config.vscodePort),
762 OH_SECRET_KEY: config.secretKey,
763 // Use OH_SESSION_API_KEYS_0 for agent-server V1 config format
764 OH_SESSION_API_KEYS_0: config.sessionApiKey,
765 // Alias for the agent-server's own URL. The agent-server itself sets
766 // OH_INTERNAL_SERVER_URL at startup, but downstream consumers (the
767 // OpenHands SDK boilerplate emitted by automation prompt/plugin
768 // presets) read AGENT_SERVER_URL — the canonical SDK name. Mirror it
769 // here so automation runs work without each tarball having to know
770 // about the OH_-prefixed variant.
771 //
772 // We deliberately do NOT set a SESSION_API_KEY alias: the SDK's
773 // sanitized_env() would strip it from bash subprocesses anyway, and
774 // a follow-up change to the automation preset reads
775 // OH_SESSION_API_KEYS_0 directly (which is already in env).
776 AGENT_SERVER_URL: config.backendBaseUrl,
777 // Let the agent-server resolve canvas_ui_tool when old persisted metadata
778 // requests that compatibility module during startup.
779 OH_EXTRA_PYTHON_PATH: config.canvasToolsDir,
780 };
781}
782
783// Re-export so existing importers (dev-with-automation.mjs, tests) keep
784// resolving `buildRuntimeServicesInfo` from this module. The implementation

Callers 5

startAgentServerFunction · 0.90
mainFunction · 0.90
startAgentServerFunction · 0.90
dev-safe.test.tsFile · 0.90
mainFunction · 0.85

Calls 1

Tested by

no test coverage detected