{"record":{"id":"a5261e69529ad2d6","repo":"langchain-ai/deepagents","slug":"timeout-must-be-non-negative-got-timeout","errorCode":null,"errorMessage":"timeout must be non-negative, got {timeout}","messagePattern":"timeout must be non-negative, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/partners/vercel/langchain_vercel_sandbox/sandbox.py","lineNumber":53,"sourceCode":"        self,\n        *,\n        sandbox: Sandbox,\n        timeout: int = 30 * 60,\n    ) -> None:\n        \"\"\"Create a backend wrapping an existing Vercel sandbox.\n\n        Args:\n            sandbox: Existing Vercel sandbox instance to wrap.\n            timeout: Default command timeout in seconds used when `execute()` is\n                called without an explicit `timeout`. A timeout of 0 waits\n                indefinitely; negative values are rejected.\n\n        Raises:\n            ValueError: If `timeout` is negative.\n        \"\"\"\n        if timeout < 0:\n            msg = f\"timeout must be non-negative, got {timeout}\"\n            raise ValueError(msg)\n        self._sandbox = sandbox\n        self._default_timeout = timeout\n\n    @property\n    def id(self) -> str:\n        \"\"\"Return the Vercel sandbox id.\"\"\"\n        return self._sandbox.sandbox_id\n\n    def execute(\n        self,\n        command: str,\n        *,\n        timeout: int | None = None,\n    ) -> ExecuteResponse:\n        \"\"\"Execute a shell command inside the sandbox.\n\n        Args:\n            command: Shell command string to execute.","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/partners/vercel/langchain_vercel_sandbox/sandbox.py#L35-L71","documentation":"`VercelSandbox.__init__` validates the `timeout` parameter and raises `ValueError` if it is negative. The timeout is the default maximum duration in seconds for sandbox operations, so a negative value is always a programming/config error and is rejected eagerly rather than surfacing later inside an operation.","triggerScenarios":"Constructing `VercelSandbox(sandbox=..., timeout=n)` with a negative `n` — typically from an unvalidated config file, env var, or computed duration (e.g. `deadline - now` after the deadline has passed).","commonSituations":"Config parsing that doesn't clamp values (`timeout: -1` in YAML/TOML); subtracting timestamps where the deadline already elapsed; sign errors when converting minutes to seconds.","solutions":["Fix the caller/config so `timeout >= 0`; clamp with `max(0, value)`.","Validate the configured timeout at config-load time before constructing the sandbox.","Use `timeout=0` (or omit it for the default) if you truly want no/immediate timeout semantics.","Audit computed values like `deadline - now` and guard against elapsed deadlines."],"exampleFix":"// before\ntimeout = int(os.environ[\"VERCEL_TIMEOUT\"])  # may be -1\nsb = VercelSandbox(sandbox=vs, timeout=timeout)  # ValueError\n\n// after\ntimeout = max(0, int(os.environ.get(\"VERCEL_TIMEOUT\", 300)))\nsb = VercelSandbox(sandbox=vs, timeout=timeout)","handlingStrategy":"validation","validationCode":"def normalize_timeout(value: int | float | str | None, default: int = 300) -> int:\n    if value is None:\n        return default\n    return max(0, int(value))","typeGuard":"def is_valid_timeout(timeout: int) -> bool:\n    return isinstance(timeout, int) and timeout >= 0","tryCatchPattern":"try:\n    sb = VercelSandbox(sandbox=vs, timeout=timeout)\nexcept ValueError as e:\n    log.error(\"bad timeout config: %s\", e)\n    sb = VercelSandbox(sandbox=vs, timeout=300)","preventionTips":["Validate/clamp timeout values at config-load time, not at sandbox construction.","Use non-negative types or sentinel defaults for deadline-derived durations; guard `deadline - now` against elapsed deadlines.","Add a schema/unit check for timeout fields in config files (>= 0).","Prefer omitting `timeout` to accept the library default unless you need a custom cap."],"tags":["python","validation","vercel","valueerror","timeout"],"backgroundTag":"invalid-parameter-value","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}