{"record":{"id":"accd6b0e4291e5df","repo":"iflytek/astron-agent","slug":"sandbox-initialization-failed","errorCode":null,"errorMessage":"Sandbox initialization failed","messagePattern":"Sandbox initialization failed","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"core/agent/service/plugin/skill_sandbox.py","lineNumber":573,"sourceCode":"        self.config = config or SkillSandboxConfig()\n\n    async def execute(self, request: SandboxExecutionRequest) -> dict[str, Any]:\n        from e2b import AsyncSandbox\n\n        (\n            api_key,\n            execution_timeout,\n            allow_internet_access,\n        ) = await _fetch_e2b_runtime_config(self.config)\n        try:\n            sandbox = await AsyncSandbox.create(\n                api_key=api_key,\n                timeout=execution_timeout,\n                allow_internet_access=allow_internet_access,\n                metadata={\"skill_id\": request.skill_id},\n            )\n        except Exception:\n            raise RuntimeError(SANDBOX_INITIALIZATION_ERROR) from None\n        finally:\n            api_key = \"\"\n        try:\n            workspace = \"/home/user/skill\"\n            await self._stage_resources(sandbox, workspace, request.resources)\n            cmd = request.command\n            if request.stdin is not None:\n                stdin_path = f\"{workspace}/.astron_stdin.json\"\n                await sandbox.files.write(\n                    stdin_path, json.dumps(request.stdin, ensure_ascii=False)\n                )\n                cmd = f\"{cmd} < .astron_stdin.json\"\n            exit_code, stdout, stderr = await _run_command_with_bounded_output(\n                sandbox,\n                cmd,\n                cwd=self._join_workspace(workspace, request.working_dir),\n                timeout_seconds=execution_timeout,\n            )","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/agent/service/plugin/skill_sandbox.py#L555-L591","documentation":"E2BSandboxProvider.execute creates an E2B AsyncSandbox with the fetched API key, timeout, and internet-access flag. Any exception during AsyncSandbox.create is swallowed and re-raised as RuntimeError(SANDBOX_INITIALIZATION_ERROR) ('Sandbox initialization failed'), deliberately hiding SDK internals from callers.","triggerScenarios":"Invalid/missing E2B API key, expired quota or billing limit, unreachable E2B API, invalid timeout value, unsupported allow_internet_access option, or e2b package import failure — anything that makes AsyncSandbox.create raise.","commonSituations":"E2B_API_KEY not set or rotated in the environment; org out of sandbox credits; network egress blocked from the service to e2b endpoints; e2b SDK version incompatibility with the API; timeout configured as 0/negative.","solutions":["Check that the E2B API key is configured, valid, and not expired; test with a minimal AsyncSandbox.create call","Verify E2B account quota/billing and region status in the E2B dashboard","Check network egress/DNS from the service to the E2B API endpoint","Pin/upgrade the e2b SDK to a version compatible with the deployed API and confirm the timeout value is a positive number of seconds"],"exampleFix":"// before: key sourced from unset var\nsandbox = await AsyncSandbox.create(api_key=os.environ.get('E2B_API_KEY'), timeout=0)\n// after\nkey = os.environ['E2B_API_KEY']\nassert key, 'E2B_API_KEY is required'\nsandbox = await AsyncSandbox.create(api_key=key, timeout=execution_timeout)","handlingStrategy":"try-catch","validationCode":"import os\nkey = os.environ.get('E2B_API_KEY')\nif not key:\n    raise RuntimeError('E2B_API_KEY missing; sandbox cannot start')\nif execution_timeout is None or execution_timeout <= 0:\n    raise RuntimeError('execution_timeout must be positive')","typeGuard":"def e2b_config_ok(key: str | None, timeout: int | None) -> bool:\n    return bool(key) and isinstance(timeout, int) and timeout > 0","tryCatchPattern":"try:\n    result = await provider.execute(request)\nexcept RuntimeError as e:\n    if 'Sandbox initialization failed' in str(e):\n        logger.error('E2B sandbox create failed; check API key/quota/network')\n        raise\n    raise","preventionTips":["Keep E2B_API_KEY set in all deploy environments and rotate safely","Monitor E2B quota/billing alerts","Pin the e2b SDK version and test sandbox creation in CI","Verify network egress to E2B endpoints from your cluster"],"tags":["sandbox","e2b","initialization","configuration","authentication"],"backgroundTag":"module-init-failed","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}