iflytek/astron-agent · critical · RuntimeError

Sandbox initialization failed

Error message

Sandbox initialization failed

What it means

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.

Solutions

  1. Check that the E2B API key is configured, valid, and not expired; test with a minimal AsyncSandbox.create call
  2. Verify E2B account quota/billing and region status in the E2B dashboard
  3. Check network egress/DNS from the service to the E2B API endpoint
  4. Pin/upgrade the e2b SDK to a version compatible with the deployed API and confirm the timeout value is a positive number of seconds

Example fix

// before: key sourced from unset var
sandbox = await AsyncSandbox.create(api_key=os.environ.get('E2B_API_KEY'), timeout=0)
// after
key = os.environ['E2B_API_KEY']
assert key, 'E2B_API_KEY is required'
sandbox = await AsyncSandbox.create(api_key=key, timeout=execution_timeout)
Defensive patterns

Strategy: try-catch

Validate before calling

import os
key = os.environ.get('E2B_API_KEY')
if not key:
    raise RuntimeError('E2B_API_KEY missing; sandbox cannot start')
if execution_timeout is None or execution_timeout <= 0:
    raise RuntimeError('execution_timeout must be positive')

Type guard

def e2b_config_ok(key: str | None, timeout: int | None) -> bool:
    return bool(key) and isinstance(timeout, int) and timeout > 0

Try / catch

try:
    result = await provider.execute(request)
except RuntimeError as e:
    if 'Sandbox initialization failed' in str(e):
        logger.error('E2B sandbox create failed; check API key/quota/network')
        raise
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/accd6b0e4291e5df. Report an issue: GitHub.

Appendix: source

Thrown at core/agent/service/plugin/skill_sandbox.py:573

        self.config = config or SkillSandboxConfig()

    async def execute(self, request: SandboxExecutionRequest) -> dict[str, Any]:
        from e2b import AsyncSandbox

        (
            api_key,
            execution_timeout,
            allow_internet_access,
        ) = await _fetch_e2b_runtime_config(self.config)
        try:
            sandbox = await AsyncSandbox.create(
                api_key=api_key,
                timeout=execution_timeout,
                allow_internet_access=allow_internet_access,
                metadata={"skill_id": request.skill_id},
            )
        except Exception:
            raise RuntimeError(SANDBOX_INITIALIZATION_ERROR) from None
        finally:
            api_key = ""
        try:
            workspace = "/home/user/skill"
            await self._stage_resources(sandbox, workspace, request.resources)
            cmd = request.command
            if request.stdin is not None:
                stdin_path = f"{workspace}/.astron_stdin.json"
                await sandbox.files.write(
                    stdin_path, json.dumps(request.stdin, ensure_ascii=False)
                )
                cmd = f"{cmd} < .astron_stdin.json"
            exit_code, stdout, stderr = await _run_command_with_bounded_output(
                sandbox,
                cmd,
                cwd=self._join_workspace(workspace, request.working_dir),
                timeout_seconds=execution_timeout,
            )

View on GitHub (pinned to 5e758547a8)