{"record":{"id":"f1ef64073c4f5150","repo":"BerriAI/litellm","slug":"validate-environment-must-be-implemented-by-provid","errorCode":null,"errorMessage":"validate_environment must be implemented by provider","messagePattern":"validate_environment must be implemented by provider","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"litellm/llms/base_llm/sandbox/transformation.py","lineNumber":50,"sourceCode":"    \"\"\"Passthrough of the sandbox's own execution output.\"\"\"\n\n    stdout: str = \"\"\n    stderr: str = \"\"\n    results: list[dict[str, Any]] = Field(default_factory=list)\n    error: dict[str, Any] | None = None\n    execution_count: int | None = None\n    object: str = \"code_execution\"\n\n    model_config = {\"extra\": \"allow\"}\n\n    _hidden_params: dict = PrivateAttr(default_factory=dict)\n\n\nclass BaseSandboxConfig:\n    \"\"\"Provider-agnostic sandbox operations.\"\"\"\n\n    def validate_environment(self, api_key: str | None = None, **kwargs) -> str:\n        raise NotImplementedError(\"validate_environment must be implemented by provider\")\n\n    async def acreate_sandbox(\n        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,","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/base_llm/sandbox/transformation.py#L32-L68","documentation":"BaseSandboxConfig is the provider-agnostic base class for LiteLLM's sandbox (code-execution container) integration. validate_environment() is intentionally a stub that raises NotImplementedError; every concrete provider (e.g. OpenSandbox, E2B) must override it to resolve and return the API key from the environment. Hitting this means the code path was instantiated with the base class (or a subclass that never implemented the method) instead of a real provider config.","triggerScenarios":"Using litellm's sandbox/code-execution API where the resolved provider config is BaseSandboxConfig itself — e.g. registering a custom sandbox provider that subclasses BaseSandboxConfig but does not override validate_environment, or a provider string that fails to map to a concrete sandbox transformation and falls back to the base.","commonSituations":"Writing a custom sandbox provider and forgetting to implement validate_environment; upgrading litellm versions where the sandbox base-class contract gained new abstract-like methods; passing an unsupported sandbox provider name.","solutions":["Use a built-in concrete provider config (e.g. OpenSandboxConfig from litellm/llms/opensandbox or the E2B config) instead of the base class.","If you subclass BaseSandboxConfig for a custom provider, implement validate_environment(self, api_key=None, **kwargs) -> str to fetch/validate the key (typically from kwargs['api_key'] or an env var) and return it.","Check that the provider name you pass maps to a registered sandbox handler and is not silently falling back to the default config."],"exampleFix":"# before\nclass MySandbox(BaseSandboxConfig):\n    pass  # NotImplementedError at runtime\n\n# after\nclass MySandbox(BaseSandboxConfig):\n    def validate_environment(self, api_key: str | None = None, **kwargs) -> str:\n        key = api_key or os.getenv(\"MY_SANDBOX_API_KEY\")\n        if not key:\n            raise ValueError(\"MY_SANDBOX_API_KEY not set\")\n        return key","handlingStrategy":"type-guard","validationCode":"from litellm.llms.base_llm.sandbox.transformation import BaseSandboxConfig\n\n# before use, assert the config actually implements the interface\nassert type(cfg).validate_environment is not BaseSandboxConfig.validate_environment, \"provider lacks validate_environment\"","typeGuard":"from litellm.llms.base_llm.sandbox.transformation import BaseSandboxConfig\n\ndef sandbox_config_is_complete(cfg: BaseSandboxConfig) -> bool:\n    return all(\n        getattr(type(cfg), m) is not getattr(BaseSandboxConfig, m)\n        for m in (\"validate_environment\", \"acreate_sandbox\", \"arun_code\", \"adelete_sandbox\")\n    )","tryCatchPattern":null,"preventionTips":["Never instantiate BaseSandboxConfig directly; always use a concrete provider config.","Add a unit test that calls every sandbox hook on each custom config to catch missing overrides at CI time.","Use typing.Protocol + runtime_checkable for custom sandbox providers so incompleteness fails at instantiation."],"tags":["sandbox","not-implemented","abstract-method","litellm"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}