When you use sandbox.exec / launch_process with the argument cwd pointing to an invalid path, you get an http500 error:
CommandResult(stdout='', stderr='Command execution failed: 500 Server Error: Internal Server Error for url: https://<redacted>.koyeb.app/koyeb-sandbox/run', exit_code=1, status=<CommandStatus.FAILED: 'failed'>, duration=0.172882080078125, command='id', args=[])
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
File ~/<redacted>/.venv/lib/python3.13/site-packages/koyeb/sandbox/sandbox.py:892, in Sandbox.launch_process(self, cmd, cwd, env)
891 try:
--> 892 response = client.start_process(cmd, cwd, env)
893 # Check for process ID - if it exists, the process was launched successfully
File ~/<redacted>/.venv/lib/python3.13/site-packages/koyeb/sandbox/executor_client.py:458, in SandboxClient.start_process(self, cmd, cwd, env)
456 payload["env"] = env
--> 458 response = self._request_with_retry(
459 "POST", f"{self.base_url}/start_process", json=payload, headers=self.headers
460 )
461 return response.json()
File ~/<redacted>/.venv/lib/python3.13/site-packages/koyeb/sandbox/executor_client.py:129, in SandboxClient._request_with_retry(self, method, url, max_retries, initial_backoff, **kwargs)
127 continue
--> 129 response.raise_for_status()
130 return response
File ~/<redacted>/.venv/lib/python3.13/site-packages/requests/models.py:1026, in Response.raise_for_status(self)
1025 if http_error_msg:
-> 1026 raise HTTPError(http_error_msg, response=self)
HTTPError: 500 Server Error: Internal Server Error for url: https://<redacted>.koyeb.app/koyeb-sandbox/start_process
The above exception was the direct cause of the following exception:
SandboxError Traceback (most recent call last)
Cell In[24], line 1
----> 1 sandbox.launch_process('id', cwd='/invalid/path')
File ~/<redacted>/.venv/lib/python3.13/site-packages/koyeb/sandbox/sandbox.py:903, in Sandbox.launch_process(self, cmd, cwd, env)
901 if isinstance(e, SandboxError):
902 raise
--> 903 raise SandboxError(f"Failed to launch process: {str(e)}") from e
SandboxError: Failed to launch process: 500 Server Error: Internal Server Error for url: https://<redacted>.koyeb.app/koyeb-sandbox/start_process
Would it be possible to return a 4XX error instead and handle it in the library ?
When you use sandbox.exec / launch_process with the argument cwd pointing to an invalid path, you get an http500 error:
Would it be possible to return a 4XX error instead and handle it in the library ?