Skip to content

Raise SandboxError when the sandbox URL is unavailable - #59

Merged
sfroment merged 1 commit into
koyeb:mainfrom
pedroCollogno:fix/sandbox-client-raises-on-missing-url
Aug 27, 2026
Merged

Raise SandboxError when the sandbox URL is unavailable#59
sfroment merged 1 commit into
koyeb:mainfrom
pedroCollogno:fix/sandbox-client-raises-on-missing-url

Conversation

@pedroCollogno

@pedroCollogno pedroCollogno commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Issue

  • Sandbox._get_client and AsyncSandbox._get_async_client unpack _get_sandbox_url() with no None-guard.
  • For a gone sandbox the metadata/domain lookups swallow the NotFoundException and return None
  • --> so the unpack raises a raw TypeError: cannot unpack non-iterable NoneType object instead of the SandboxError that _get_client's docstring already promises.
  • --> It surfaces on the sandbox.exec() path via _get_async_client(), so callers can't tell a gone sandbox from an unrelated bug.

Fix

Guard the None case in both the sync and async client getters and raise SandboxError, matching the documented contract, so callers can detect a gone sandbox via the typed error.

  • Adds koyeb/sandbox/test_sandbox_client.py: asserts both getters raise SandboxError (not TypeError) when the URL is unavailable, plus happy-path cases confirming a resolvable URL still unpacks and builds ConnectionInfo.

@pedroCollogno
pedroCollogno force-pushed the fix/sandbox-client-raises-on-missing-url branch from 9a63479 to e1f5ada Compare August 27, 2026 10:07
_get_client / _get_async_client unpacked _get_sandbox_url() with no
None-guard. For a gone sandbox the metadata/domain lookups swallow the
NotFoundException and return None, so _get_sandbox_url() returns None and
the unpack raised a raw `TypeError: cannot unpack non-iterable NoneType
object` instead of the SandboxError the docstring promises.

Guard the None case in both the sync and async client getters and raise
SandboxError, so callers can detect a gone sandbox via the typed error.
@pedroCollogno
pedroCollogno force-pushed the fix/sandbox-client-raises-on-missing-url branch from e1f5ada to 69099ac Compare August 27, 2026 12:19
Comment thread koyeb/sandbox/sandbox.py
def _get_conn_info(self) -> ConnectionInfo:
"""
Internal method to get the parameters needed to connect to the sandbox.
Caches the info after first retrieval.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, not accurate

@sfroment sfroment left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sfroment
sfroment merged commit 9b973b6 into koyeb:main Aug 27, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants