{"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/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/code_interpreter_interception/handler.py#L740-L776","documentation":"ValueError from CodeInterpreterInterception._run_code: after a container exists, code execution requires either a sandbox_config or the SandboxToolParams captured when the container was created. If params is None and sandbox_config is None, the handler cannot determine which provider API to call and raises. This indicates an inconsistent state — usually containers created via sandbox_config that was later cleared, or a container handle passed in from elsewhere without its params.","triggerScenarios":"Calling _run_code with a ContainerHandle obtained from outside _create_container (so no SandboxToolParams accompany it) while handler.sandbox_config is None; mutating handler.sandbox_config to None after containers were cached; subclass overriding _create_container to return (container, None).","commonSituations":"Custom integrations reusing the interception handler with externally provisioned containers; tests constructing fake ContainerHandles directly; refactors that move sandbox_config initialization after container creation.","solutions":["Always obtain (container, params) as a pair from _create_container and pass both to _run_code","Set sandbox_config on the handler so it is the single source of truth for run/delete operations","If you provision containers yourself, also construct/pass matching SandboxToolParams","Don't clear or reassign sandbox_config while cached containers are still in use"],"exampleFix":"# before\ncontainer = await handler._create_container()[0]\nresult = await handler._run_code(container, None, code)  # ValueError\n\n# after\ncontainer, params = await handler._create_container()\nresult = await handler._run_code(container, params, code)","handlingStrategy":"validation","validationCode":"def can_run_code(handler, params) -> bool:\n    return handler.sandbox_config is not None or params is not None","typeGuard":null,"tryCatchPattern":"try:\n    result = await handler._run_code(container, params, code)\nexcept ValueError as e:\n    if \"no sandbox available to run code\" in str(e):\n        raise RuntimeError(\"Container/params mismatch — always pair them from _create_container\") from e\n    raise","preventionTips":["Always destructure (container, params) together from _create_container","Never null out sandbox_config while cached containers are live","If provisioning containers externally, pass matching SandboxToolParams explicitly"],"tags":["code-interpreter","sandbox","state-management"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}