{"record":{"id":"abb45982362e95ee","repo":"microsoft/aspire","slug":"remote-app-host-socket-path-environment-variable-not-set-run-abb459","errorCode":null,"errorMessage":"REMOTE_APP_HOST_SOCKET_PATH environment variable not set. Run this application using `aspire run`.","messagePattern":"REMOTE_APP_HOST_SOCKET_PATH environment variable not set\\. Run this application using `aspire run`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.CodeGeneration.Python/PythonModuleBuilder.cs","lineNumber":1811,"sourceCode":"            def run(self, *, timeout: int | None = None) -> None:\n                '''Builds and runs the distributed application.'''\n                app = self.build()\n                app.run(timeout=timeout)\n\n        \"\"\";\n\n    /// <summary>\n    /// Connection helper code for creating the Aspire client and builder.\n    /// </summary>\n    public const string ConnectionHelperCode = \"\"\"\n        def _get_client(*, debug: bool, heartbeat_interval: int | None) -> AspireClient:\n            '''\n            Creates and connects to the Aspire AppHost.\n            Reads connection info from environment variables set by `aspire run`.\n            '''\n            socket_path = os.environ.get('REMOTE_APP_HOST_SOCKET_PATH')\n            if not socket_path:\n                raise ValueError(\n                    'REMOTE_APP_HOST_SOCKET_PATH environment variable not set. '\n                    'Run this application using `aspire run`.'\n                )\n\n            client = AspireClient(socket_path, debug=debug, heartbeat_interval=heartbeat_interval)\n            client.connect()\n            auth_token = os.environ.get('ASPIRE_REMOTE_APPHOST_TOKEN')\n            if not auth_token:\n                raise ValueError(\n                    'ASPIRE_REMOTE_APPHOST_TOKEN environment variable not set. '\n                    'Run this application using `aspire run`.'\n                )\n            client.authenticate(auth_token)\n            return client\n\n\n        def create_builder(\n            *,","sourceCodeStart":1793,"sourceCodeEnd":1829,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.Python/PythonModuleBuilder.cs#L1793-L1829","documentation":"The Python remote client reads its connection endpoint from the REMOTE_APP_HOST_SOCKET_PATH environment variable, which `aspire run` sets for the processes it launches. When absent it raises ValueError telling the developer to launch via `aspire run`.","triggerScenarios":"Running the Python app directly (`python app.py`, IDE run button, debugger, plain container) instead of through `aspire run`, or spawning it from a context that did not inherit the env var.","commonSituations":"Debugging in VS Code/PyCharm which launches the interpreter directly; running inside Docker without passing the env var; CI jobs invoking the script without the Aspire CLI wrapper.","solutions":["Start the application with `aspire run` so the AppHost injects REMOTE_APP_HOST_SOCKET_PATH.","If running under a debugger, configure the launch profile/task to use `aspire run` as the launch command.","Manually set REMOTE_APP_HOST_SOCKET_PATH to the AppHost socket path when launching out-of-band.","Ensure the parent process that spawns the app propagates its environment (no stripped env)."],"exampleFix":"# before\npython app.py\n# after\naspire run","handlingStrategy":"validation","validationCode":"import os\nif not os.environ.get(\"REMOTE_APP_HOST_SOCKET_PATH\"):\n    raise SystemExit(\"launch with `aspire run` (missing REMOTE_APP_HOST_SOCKET_PATH)\")","typeGuard":"def can_connect() -> bool:\n    return bool(os.environ.get(\"REMOTE_APP_HOST_SOCKET_PATH\"))","tryCatchPattern":"try:\n    client = connect_aspire()\nexcept ValueError:\n    raise SystemExit(\"start the app with `aspire run` instead of running it directly\")","preventionTips":["Always launch through `aspire run`.","Configure IDE debuggers to use aspire run as the launch command.","Propagate the parent environment when spawning the app."],"tags":["python","environment","env-var","aspire-run"],"backgroundTag":"missing-env-var","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}