{"record":{"id":"06dedb94acb2cf7c","repo":"iflytek/astron-agent","slug":"artifact-upload-credential-is-missing-or-invalid-e2b","errorCode":null,"errorMessage":"Artifact upload credential is missing or invalid","messagePattern":"Artifact upload credential is missing or invalid","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"core/workflow/engine/nodes/code/executor/e2b/e2b_executor.py","lineNumber":156,"sourceCode":"        pass\n    print('{\"error\":\"snapshot_failed\"}')\nfinally:\n    if source_fd is not None:\n        os.close(source_fd)\n    if destination_fd is not None:\n        os.close(destination_fd)\n\"\"\".strip()\n\n\ndef _load_artifact_upload_token() -> str:\n    token = (os.getenv(ARTIFACT_UPLOAD_TOKEN_ENV) or \"\").strip()\n    if not token:\n        token_file = (os.getenv(ARTIFACT_UPLOAD_TOKEN_FILE_ENV) or \"\").strip()\n        if token_file:\n            try:\n                token = Path(token_file).read_text(encoding=\"utf-8\").strip()\n            except (OSError, UnicodeError) as exc:\n                raise RuntimeError(ARTIFACT_UPLOAD_CREDENTIAL_ERROR) from exc\n    if len(token) < MIN_ARTIFACT_UPLOAD_TOKEN_LENGTH or \"\\r\" in token or \"\\n\" in token:\n        raise RuntimeError(ARTIFACT_UPLOAD_CREDENTIAL_ERROR)\n    return token\n\n\ndef _load_artifact_upload_url() -> str:\n    artifact_upload_url = (os.getenv(ARTIFACT_UPLOAD_URL_ENV) or \"\").strip()\n    try:\n        parsed = urlsplit(artifact_upload_url)\n        if (\n            not artifact_upload_url\n            or len(artifact_upload_url) > 2048\n            or any(char in artifact_upload_url for char in (\"\\r\", \"\\n\", \"\\t\"))\n            or parsed.scheme not in {\"http\", \"https\"}\n            or not parsed.hostname\n            or parsed.username is not None\n            or parsed.password is not None\n            or parsed.path != ARTIFACT_UPLOAD_PATH","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/engine/nodes/code/executor/e2b/e2b_executor.py#L138-L174","documentation":"_load_artifact_upload_token resolves the artifact-upload credential from an env var or a token file. It raises RuntimeError(ARTIFACT_UPLOAD_CREDENTIAL_ERROR) when the file named by the token-file env var cannot be read (OSError/UnicodeError), because then no usable credential exists for uploading artifacts out of the E2B sandbox.","triggerScenarios":"ARTIFACT_UPLOAD_TOKEN_FILE_ENV points to a nonexistent, unreadable, or invalid-UTF-8 file; Path.read_text raises OSError or UnicodeError during upload().","commonSituations":"Token file path misconfigured in the container, file not mounted, permissions changed, or the file contains binary/invalid encoding.","solutions":["Fix the token-file env var to point to an existing readable file, or set the token directly via the token env var.","Verify file permissions and that the volume mount is present in the deployment.","Regenerate/replace the token file with valid UTF-8 content."],"exampleFix":"// before\nARTIFACT_UPLOAD_TOKEN_FILE=/secrets/missing-token\n// after\nARTIFACT_UPLOAD_TOKEN_FILE=/etc/astron/artifact-upload-token  # file exists and is readable","handlingStrategy":"validation","validationCode":"from pathlib import Path\np = Path(os.environ[\"ARTIFACT_UPLOAD_TOKEN_FILE\"])\nassert p.is_file() and p.stat().st_size > 0, \"token file missing/empty\"\ntext = p.read_text(encoding=\"utf-8\")  # raises UnicodeError early if not UTF-8","typeGuard":null,"tryCatchPattern":"try:\n    ex.upload(...)\nexcept RuntimeError as e:\n    if \"credential\" in str(e): alert(\"artifact upload token unreadable\"); skip artifact step","preventionTips":["Mount secrets read-only at a stable path and verify at startup","Check file readability in a readiness probe","Keep token files single-line UTF-8"],"tags":["credentials","file-read","sandbox"],"backgroundTag":"file-read-failed","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}