infiniflow/ragflow · error · RuntimeError

Tenki sandbox is no longer available: {exc}

Error message

Tenki sandbox is no longer available: {exc}

What it means

RuntimeError raised when sandbox.exec() throws errors.SessionTerminatedError or errors.SessionNotFoundError: the microVM backing the instance is gone. Per the code comment, typical causes are the sandbox being reclaimed at max_lifetime or lost mid-run; it is deliberately surfaced as RuntimeError, not an SDK type.

Source

Thrown at agent/sandbox/providers/tenki.py:221

        args_json = json.dumps(arguments or {}, ensure_ascii=False)
        script_path, argv = self._prepare_script(sandbox, remote_work_dir, normalized_lang, code, args_json)

        requested_timeout = self.timeout if timeout is None else int(timeout)
        if requested_timeout <= 0:
            raise RuntimeError(f"Execution timeout must be greater than 0 seconds, got {requested_timeout}.")
        exec_timeout = min(requested_timeout, self.timeout)

        start_time = time.time()
        try:
            result = sandbox.exec(*argv, cwd=remote_work_dir, timeout=exec_timeout)
        except (errors.CommandTimeoutError, errors.PrimitiveTimeoutError) as exc:
            logger.warning("Tenki execution timed out (instance=%s, timeout=%ss)", instance_id, exec_timeout)
            raise TimeoutError(f"Execution timed out after {exec_timeout} seconds") from exc
        except (errors.SessionTerminatedError, errors.SessionNotFoundError) as exc:
            # The sandbox was reclaimed (e.g. max_lifetime) or lost mid-run;
            # surface it as RuntimeError per the base contract, not an SDK type.
            raise RuntimeError(f"Tenki sandbox is no longer available: {exc}") from exc
        except Exception as exc:
            raise RuntimeError(f"Tenki execution failed: {exc}") from exc
        execution_time = time.time() - start_time

        stdout = result.stdout_text
        stderr = result.stderr_text
        exit_code = int(result.exit_code)

        self._validate_output_size(stdout, stderr)
        stdout, structured_result = extract_structured_result(stdout)

        return ExecutionResult(
            stdout=stdout,
            stderr=stderr,
            exit_code=exit_code,
            execution_time=execution_time,
            metadata={
                "instance_id": instance_id,

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Recover by destroying the dead instance handle and create_instance() + execute_code() again (the work dir is per-instance, so re-upload/re-run the script).
  2. Keep total instance age under max_lifetime; set max_lifetime in initialize() high enough for your session length.
  3. Create a fresh instance per task instead of caching instances across long pauses.

Example fix

# before
result = provider.execute_code(instance_id, code)  # raises after max_lifetime reclaim

# after
try:
    result = provider.execute_code(instance_id, code)
except RuntimeError as exc:
    if "no longer available" not in str(exc):
        raise
    provider.destroy_instance(instance_id)
    inst = provider.create_instance(template)
    result = provider.execute_code(inst.instance_id, code)
Defensive patterns

Strategy: fallback

Validate before calling

# track instance age and refresh before max_lifetime reaps it
age = time.time() - created_at[instance_id]
if age > provider.max_lifetime - safety_margin:
    refresh_instance(instance_id)

Try / catch

try:
    result = provider.execute_code(instance_id, code)
except RuntimeError as exc:
    if "no longer available" not in str(exc):
        raise
    provider.destroy_instance(instance_id)
    inst = provider.create_instance(template)
    result = provider.execute_code(inst.instance_id, code)  # fallback: fresh sandbox

Prevention

When it happens

Trigger: Calling execute_code() on an instance whose sandbox exceeded max_lifetime (default 3600s) and was reaped by Tenki, or on an instance terminated server-side (host maintenance, eviction). The provider's in-memory _instances registry still lists it.

Common situations: Long-lived agent sessions reusing one sandbox past its lifetime, a crashed/evicted microVM, or stale instance ids after the provider process resumed from a checkpoint.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/8650ee05150ccc3a. Report an issue: GitHub.