{"record":{"id":"8b18334151575c5d","repo":"BerriAI/litellm","slug":"arun-code-must-be-implemented-by-provider","errorCode":null,"errorMessage":"arun_code must be implemented by provider","messagePattern":"arun_code must be implemented by provider","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"litellm/llms/base_llm/sandbox/transformation.py","lineNumber":71,"sourceCode":"        self,\n        *,\n        template: str | None = None,\n        timeout: int | None = None,\n        allow_internet_access: bool | None = None,\n        api_key: str | None = None,\n        **kwargs,\n    ) -> ContainerHandle:\n        raise NotImplementedError(\"acreate_sandbox must be implemented by provider\")\n\n    async def arun_code(\n        self,\n        *,\n        container: ContainerHandle | str,\n        code: str,\n        api_key: str | None = None,\n        **kwargs,\n    ) -> CodeExecutionResult:\n        raise NotImplementedError(\"arun_code must be implemented by provider\")\n\n    async def adelete_sandbox(\n        self,\n        *,\n        container: ContainerHandle | str,\n        api_key: str | None = None,\n        **kwargs,\n    ) -> bool:\n        raise NotImplementedError(\"adelete_sandbox must be implemented by provider\")\n\n    async def _read_capped_lines(self, response: httpx.Response) -> list[str]:\n        lines: Final[list[str]] = []\n        total = 0\n        async for line in response.aiter_lines():\n            total += len(line.encode(\"utf-8\"))\n            if total > SANDBOX_MAX_OUTPUT_BYTES:\n                raise ValueError(\n                    f\"Sandbox output exceeded {SANDBOX_MAX_OUTPUT_BYTES} bytes; aborting to avoid unbounded memory use.\"","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/base_llm/sandbox/transformation.py#L53-L89","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use a provider with a complete implementation (OpenSandbox or E2B) by selecting the correct provider name.","Implement `async def arun_code(self, *, container, code, api_key=None, **kwargs) -> CodeExecutionResult` in your custom subclass.","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."],"exampleFix":"# before\nsandbox = MySandbox()  # BaseSandboxConfig subclass without arun_code\nresult = await sandbox.arun_code(container=h, code=\"print(1)\")\n\n# after\nclass MySandbox(BaseSandboxConfig):\n    async def arun_code(self, *, container, code, api_key=None, **kwargs) -> CodeExecutionResult:\n        resp = await self._client.post(f\"/containers/{container.id}/exec\", json={\"code\": code})\n        resp.raise_for_status()\n        return CodeExecutionResult(**resp.json())","handlingStrategy":"type-guard","validationCode":"from litellm.llms.base_llm.sandbox.transformation import BaseSandboxConfig\n\nassert type(cfg).arun_code is not BaseSandboxConfig.arun_code, \"arun_code not implemented\"","typeGuard":"from litellm.llms.base_llm.sandbox.transformation import BaseSandboxConfig\n\ndef supports_run_code(cfg: BaseSandboxConfig) -> bool:\n    return type(cfg).arun_code is not BaseSandboxConfig.arun_code","tryCatchPattern":"try:\n    result = await cfg.arun_code(container=handle, code=src)\nexcept NotImplementedError:\n    raise RuntimeError(f\"sandbox provider {type(cfg).__name__} cannot execute code\") from None","preventionTips":["Conformance-test all four sandbox hooks together; partial implementations are the usual cause.","Gate code-execution features on a capability flag resolved from the provider config."],"tags":["sandbox","not-implemented","code-execution","litellm"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}