{"record":{"id":"73c6e79515da8758","repo":"microsoft/aspire","slug":"aspire-remote-apphost-token-environment-variable-not-set-run-73c6e7","errorCode":null,"errorMessage":"ASPIRE_REMOTE_APPHOST_TOKEN environment variable not set. Run this application using `aspire run`.","messagePattern":"ASPIRE_REMOTE_APPHOST_TOKEN 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":1820,"sourceCode":"    /// </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            *,\n            args: typing.Iterable[str] | None = None,\n            project_directory: str | None = None,\n            app_host_file_path: str | None = None,\n            container_registry_override: str | None = None,\n            disable_dashboard: bool | None = None,\n            dashboard_application_name: str | None = None,\n            allow_unsecured_transport: bool | None = None,\n            enable_resource_logging: bool | None = None,\n            options: CreateBuilderOptions | None = None,","sourceCodeStart":1802,"sourceCodeEnd":1838,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.Python/PythonModuleBuilder.cs#L1802-L1838","documentation":"After connecting over the socket, the Python remote client must authenticate using the ASPIRE_REMOTE_APPHOST_TOKEN environment variable provisioned by `aspire run`. Missing token raises ValueError before `client.authenticate` can run.","triggerScenarios":"The socket env var is present but ASPIRE_REMOTE_APPHOST_TOKEN is unset: process launched with only partial env inheritance, token stripped by a sanitizer, or a different launcher used for the child process.","commonSituations":"Custom process supervisors (systemd, supervisord, shell wrappers) dropping env vars; Docker/Kubernetes manifests listing one env var but not the other; manually exporting the socket path but forgetting the token.","solutions":["Run via `aspire run` so both env vars are set together.","Export ASPIRE_REMOTE_APPHOST_TOKEN with the AppHost-issued token when launching manually.","Audit the launcher's env filtering to ensure ASPIRE_REMOTE_APPHOST_TOKEN is propagated.","Fix container/manifest env definitions to include the token alongside the socket path."],"exampleFix":"# before\nenv = {\"REMOTE_APP_HOST_SOCKET_PATH\": socket}\nsubprocess.run([\"python\", \"app.py\"], env=env)\n# after\nenv = {\"REMOTE_APP_HOST_SOCKET_PATH\": socket, \"ASPIRE_REMOTE_APPHOST_TOKEN\": token}\nsubprocess.run([\"python\", \"app.py\"], env=env)","handlingStrategy":"validation","validationCode":"import os\nif not os.environ.get(\"ASPIRE_REMOTE_APPHOST_TOKEN\"):\n    raise SystemExit(\"launch with `aspire run` (missing ASPIRE_REMOTE_APPHOST_TOKEN)\")","typeGuard":"def is_authenticated_env() -> bool:\n    return bool(os.environ.get(\"ASPIRE_REMOTE_APPHOST_TOKEN\"))","tryCatchPattern":"try:\n    client = connect_aspire()\nexcept ValueError:\n    raise SystemExit(\"ASPIRE_REMOTE_APPHOST_TOKEN missing; run via `aspire run` or export the token\")","preventionTips":["Set both socket path and token env vars together when launching manually.","Audit supervisors/containers for env filtering that drops ASPIRE_REMOTE_APPHOST_TOKEN.","Prefer `aspire run` over manual exports."],"tags":["python","authentication","env-var","token"],"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"}