BerriAI/litellm · error · ValueError
CodeInterpreterInterception: no sandbox available to run cod
Error message
CodeInterpreterInterception: no sandbox available to run code.
What it means
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.
Source
Thrown at litellm/integrations/code_interpreter_interception/handler.py:758
raise ValueError(
"CodeInterpreterInterception: no sandbox available. Provide a "
"sandbox_config or configure a sandbox tool resolvable via "
"sandbox_tool_name."
)
container: Final = await litellm.acreate_sandbox(
provider=params["sandbox_provider"],
api_key=params.get("api_key"),
api_base=params.get("api_base"),
)
return container, params
async def _run_code(
self, container: ContainerHandle, params: SandboxToolParams | None, code: str
) -> CodeExecutionResult:
if self.sandbox_config is not None:
return await self.sandbox_config.arun_code(container=container, code=code)
if params is None:
raise ValueError("CodeInterpreterInterception: no sandbox available to run code.")
return await litellm.arun_code(
provider=params["sandbox_provider"],
container=container,
code=code,
api_key=params.get("api_key"),
)
async def _delete_container(self, container: ContainerHandle, params: SandboxToolParams | None) -> None:
try:
if self.sandbox_config is not None:
await self.sandbox_config.adelete_sandbox(container=container)
return
if params is None:
return
await litellm.adelete_sandbox(
provider=params["sandbox_provider"],
container=container,
api_key=params.get("api_key"),View on GitHub (pinned to 6c2dcb801b)
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
Example fix
# before container = await handler._create_container()[0] result = await handler._run_code(container, None, code) # ValueError # after container, params = await handler._create_container() result = await handler._run_code(container, params, code)
Defensive patterns
Strategy: validation
Validate before calling
def can_run_code(handler, params) -> bool:
return handler.sandbox_config is not None or params is not None Try / catch
try:
result = await handler._run_code(container, params, code)
except ValueError as e:
if "no sandbox available to run code" in str(e):
raise RuntimeError("Container/params mismatch — always pair them from _create_container") from e
raise Prevention
- 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
When it happens
Trigger: 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).
Common situations: Custom integrations reusing the interception handler with externally provisioned containers; tests constructing fake ContainerHandles directly; refactors that move sandbox_config initialization after container creation.
Related errors
- CodeInterpreterInterception: no sandbox available. Provide a
- validate_environment must be implemented by provider
- acreate_sandbox must be implemented by provider
- arun_code must be implemented by provider
- adelete_sandbox must be implemented by provider
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/7fc82da0f5316464.
Report an issue: GitHub.