BerriAI/litellm · error · NotImplementedError

arun_code must be implemented by provider

Error message

arun_code must be implemented by provider

What it means

BaseSandboxConfig.arun_code() is the abstract hook for executing code inside a sandbox container and returning a CodeExecutionResult. The base class raises NotImplementedError; only concrete provider configs (OpenSandbox, E2B) implement it. Seeing this error means code execution was dispatched against the unimplemented base config.

Source

Thrown at litellm/llms/base_llm/sandbox/transformation.py:71

        self,
        *,
        template: str | None = None,
        timeout: int | None = None,
        allow_internet_access: bool | None = None,
        api_key: str | None = None,
        **kwargs,
    ) -> ContainerHandle:
        raise NotImplementedError("acreate_sandbox must be implemented by provider")

    async def arun_code(
        self,
        *,
        container: ContainerHandle | str,
        code: str,
        api_key: str | None = None,
        **kwargs,
    ) -> CodeExecutionResult:
        raise NotImplementedError("arun_code must be implemented by provider")

    async def adelete_sandbox(
        self,
        *,
        container: ContainerHandle | str,
        api_key: str | None = None,
        **kwargs,
    ) -> bool:
        raise NotImplementedError("adelete_sandbox must be implemented by provider")

    async def _read_capped_lines(self, response: httpx.Response) -> list[str]:
        lines: Final[list[str]] = []
        total = 0
        async for line in response.aiter_lines():
            total += len(line.encode("utf-8"))
            if total > SANDBOX_MAX_OUTPUT_BYTES:
                raise ValueError(
                    f"Sandbox output exceeded {SANDBOX_MAX_OUTPUT_BYTES} bytes; aborting to avoid unbounded memory use."

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Use a provider with a complete implementation (OpenSandbox or E2B) by selecting the correct provider name.
  2. Implement `async def arun_code(self, *, container, code, api_key=None, **kwargs) -> CodeExecutionResult` in your custom subclass.
  3. Add an interface-completeness check (e.g. asserting not getattr(cls.arun_code, '__isabstractmethod__', False) or a test instantiating every method) in CI for custom providers.

Example fix

# before
sandbox = MySandbox()  # BaseSandboxConfig subclass without arun_code
result = await sandbox.arun_code(container=h, code="print(1)")

# after
class MySandbox(BaseSandboxConfig):
    async def arun_code(self, *, container, code, api_key=None, **kwargs) -> CodeExecutionResult:
        resp = await self._client.post(f"/containers/{container.id}/exec", json={"code": code})
        resp.raise_for_status()
        return CodeExecutionResult(**resp.json())
Defensive patterns

Strategy: type-guard

Validate before calling

from litellm.llms.base_llm.sandbox.transformation import BaseSandboxConfig

assert type(cfg).arun_code is not BaseSandboxConfig.arun_code, "arun_code not implemented"

Type guard

from litellm.llms.base_llm.sandbox.transformation import BaseSandboxConfig

def supports_run_code(cfg: BaseSandboxConfig) -> bool:
    return type(cfg).arun_code is not BaseSandboxConfig.arun_code

Try / catch

try:
    result = await cfg.arun_code(container=handle, code=src)
except NotImplementedError:
    raise RuntimeError(f"sandbox provider {type(cfg).__name__} cannot execute code") from None

Prevention

When it happens

Trigger: Invoking run-code execution against a sandbox whose provider config lacks an arun_code override — typically a custom BaseSandboxConfig subclass or a misregistered provider handler.

Common situations: Building a custom code-execution backend and finishing only part of the interface; refactoring from sync to async sandbox APIs in a litellm upgrade; forgetting that the base class has no default implementation.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/8b18334151575c5d. Report an issue: GitHub.