{"record":{"id":"7fc82da0f5316464","repo":"BerriAI/litellm","slug":"codeinterpreterinterception-no-sandbox-available-7fc82d","errorCode":null,"errorMessage":"CodeInterpreterInterception: no sandbox available to run code.","messagePattern":"CodeInterpreterInterception: no sandbox available to run code\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/code_interpreter_interception/handler.py","lineNumber":758,"sourceCode":"            raise ValueError(\n                \"CodeInterpreterInterception: no sandbox available. Provide a \"\n                \"sandbox_config or configure a sandbox tool resolvable via \"\n                \"sandbox_tool_name.\"\n            )\n        container: Final = await litellm.acreate_sandbox(\n            provider=params[\"sandbox_provider\"],\n            api_key=params.get(\"api_key\"),\n            api_base=params.get(\"api_base\"),\n        )\n        return container, params\n\n    async def _run_code(\n        self, container: ContainerHandle, params: SandboxToolParams | None, code: str\n    ) -> CodeExecutionResult:\n        if self.sandbox_config is not None:\n            return await self.sandbox_config.arun_code(container=container, code=code)\n        if params is None:\n            raise ValueError(\"CodeInterpreterInterception: no sandbox available to run code.\")\n        return await litellm.arun_code(\n            provider=params[\"sandbox_provider\"],\n            container=container,\n            code=code,\n            api_key=params.get(\"api_key\"),\n        )\n\n    async def _delete_container(self, container: ContainerHandle, params: SandboxToolParams | None) -> None:\n        try:\n            if self.sandbox_config is not None:\n                await self.sandbox_config.adelete_sandbox(container=container)\n                return\n            if params is None:\n                return\n            await litellm.adelete_sandbox(\n                provider=params[\"sandbox_provider\"],\n                container=container,\n                api_key=params.get(\"api_key\"),","sourceCodeStart":740,"sourceCodeEnd":776,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/code_interpreter_interception/handler.py#L740-L776","documentation":"_run_code() dispatches to sandbox_config.arun_code when sandbox_config is set; otherwise it needs the SandboxToolParams that _create_container() captured when the container was created (it holds provider/api_key). The ValueError fires when sandbox_config is None AND params is None — a state that normally cannot occur from _create_container(), so it indicates the sandbox_config was cleared or the container/params pairing was broken between creation and execution (e.g. mutating the logger config mid-session or a custom subclass bypassing the factory).","triggerScenarios":"Setting logger.sandbox_config = None after containers were created; a subclass or cache path that produces a container without SandboxToolParams; restoring or hand-crafting a ContainerHandle and calling _run_code directly with params=None.","commonSituations":"Hot-reloading or reconfiguring the interception callback while cached containers exist; custom integrations wrapping the handler and dropping the params tuple element.","solutions":["Keep sandbox_config set for the logger's whole lifetime — do not mutate it after containers are created","If configuring per-request, create a fresh CodeInterpreterInterceptionLogger instead of mutating one","If you wrap _create_container/_run_code, always pass through the (container, params) pair unchanged"],"exampleFix":"# before\ncontainer, params = await logger._create_container()\nlogger.sandbox_config = None  # cleared mid-session\nawait logger._run_code(container, params, code)  # params is None when created via config -> ValueError\n\n# after\ncontainer, params = await logger._create_container()\nawait logger._run_code(container, params, code)  # config and params kept consistent","handlingStrategy":"validation","validationCode":"if logger.sandbox_config is None and params is None:\n    raise RuntimeError('cannot run code: sandbox config was cleared after container creation')\nresult = await logger._run_code(container, params, code)","typeGuard":"def can_run_code(logger, params) -> bool:\n    return logger.sandbox_config is not None or params is not None","tryCatchPattern":"except ValueError as e:\n    if 'no sandbox available to run code' in str(e):\n        recreate container via _create_container() with a consistent config, then retry once\n    else:\n        raise","preventionTips":["Treat CodeInterpreterInterceptionLogger config as immutable after construction","Always keep the (container, params) pair from _create_container together","Create a fresh logger per distinct sandbox configuration"],"tags":["sandbox","code-interpreter","state-consistency","litellm"],"backgroundTag":"missing-required-config","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}