{"record":{"id":"7ee6afa68846d311","repo":"langchain-ai/deepagents","slug":"sandbox-id","errorCode":null,"errorMessage":"{sandbox_id}","messagePattern":"\\{sandbox_id\\}","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"libs/partners/runloop/langchain_runloop/provider.py","lineNumber":191,"sourceCode":"            KeyError: If `sandbox_id` does not refer to an existing devbox\n                (the SDK's `NotFoundError` is translated to `KeyError` so\n                callers can map a missing sandbox without importing the SDK).\n            RuntimeError: If devbox or blueprint creation fails.\n        \"\"\"\n        if kwargs:\n            msg = f\"Received unsupported arguments: {list(kwargs.keys())}\"\n            raise TypeError(msg)\n\n        dockerfile = blueprint_dockerfile or _DEFAULT_BLUEPRINT_DOCKERFILE\n\n        if sandbox_id is not None:\n            try:\n                devbox = self._sdk.devbox.from_id(sandbox_id)\n            except NotFoundError as e:\n                # Translate the SDK's not-found error into a stable KeyError so\n                # callers (e.g. the deepagents-code factory) can detect a\n                # missing sandbox without importing runloop_api_client.\n                raise KeyError(sandbox_id) from e\n            return RunloopSandbox(devbox=devbox)\n\n        env_blueprint_id = self._resolve_env(\"RUNLOOP_SANDBOX_BLUEPRINT_ID\")\n        env_blueprint_name = self._resolve_env(\"RUNLOOP_SANDBOX_BLUEPRINT_NAME\")\n        blueprint_name = snapshot or env_blueprint_name\n        use_blueprint = env_blueprint_id is not None or blueprint_name is not None\n\n        try:\n            if use_blueprint:\n                devbox = self._create_from_blueprint(\n                    blueprint_id=env_blueprint_id,\n                    blueprint_name=blueprint_name,\n                    dockerfile=dockerfile,\n                )\n            else:\n                devbox = self._sdk.devbox.create()\n        except (AuthenticationError, PermissionDeniedError) as e:\n            msg = (","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/partners/runloop/langchain_runloop/provider.py#L173-L209","documentation":"When `get_or_create` is given a `sandbox_id` that Runloop does not recognize, the provider catches the SDK's `NotFoundError` and re-raises it as a plain `KeyError(sandbox_id)`. The KeyError is a stable, dependency-free signal that the devbox does not exist (or is not accessible with the current credentials), so callers can detect a missing sandbox without importing `runloop_api_client`.","triggerScenarios":"Calling `provider.get_or_create(sandbox_id=\"...\")` where the ID was already deleted (devboxes are ephemeral), never existed, was mistyped/truncated, or belongs to a different Runloop account/project.","commonSituations":"Reattaching to a devbox ID persisted from a previous session after it was shut down; copy-paste errors in the ID; using an ID from a different API key's workspace.","solutions":["Check the KeyError value: the sandbox ID is the message — verify it against your records.","Call `get_or_create()` with no `sandbox_id` to create a fresh devbox instead.","Verify the ID against the Runloop dashboard and confirm you are using the same API key/account that owns the devbox.","Wrap the call in try/except KeyError and implement create-on-missing logic.","List current devboxes via the SDK to find the correct ID."],"exampleFix":"// before\ncode = provider.get_or_create(sandbox_id=\"dbx_abc\")\n\n// after\ntry:\n    code = provider.get_or_create(sandbox_id=saved_id)\nexcept KeyError:\n    code = provider.get_or_create()  # devbox gone; create a new one","handlingStrategy":"try-catch","validationCode":"def sandbox_id_looks_valid(sandbox_id: str) -> bool:\n    return bool(sandbox_id) and sandbox_id.startswith(\"dbx_\")","typeGuard":"def is_existing_sandbox_result(result: object) -> bool:\n    return not isinstance(result, KeyError)","tryCatchPattern":"try:\n    sandbox = provider.get_or_create(sandbox_id=saved_id)\nexcept KeyError as e:\n    log.warning(\"devbox %s no longer exists; creating a new one\", e.args[0])\n    sandbox = provider.get_or_create()","preventionTips":["Always wrap attach-by-id in `except KeyError` with a create-new fallback — devboxes are ephemeral.","Never persist devbox IDs as long-lived references; re-resolve or recreate per session.","Confirm the same API key/account is used between sessions (IDs don't cross accounts).","Sanitize IDs from user input/config before calling (non-empty, correct prefix)."],"tags":["runloop","not-found","keyerror","stale-id"],"backgroundTag":"resource-not-found","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}