{"record":{"id":"6e877dbea05bbaac","repo":"agentscope-ai/agentscope","slug":"gateway-shim-exited-with-result-exit-code-resu","errorCode":null,"errorMessage":"gateway shim exited with {result.exit_code}: {result.stderr.decode(errors='replace')[:500]}","messagePattern":"gateway shim exited with (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"src/agentscope/workspace/_gateway_client.py","lineNumber":670,"sourceCode":"                        SHIM_SCRIPT,\n                        method,\n                        f\"http://127.0.0.1:{self.gateway_port}{path}\",\n                        body_file,\n                        str(self.inline_limit),\n                        self.tmp_dir,\n                        (self.auth_token or \"\") if include_auth else \"\",\n                    ],\n                    timeout=self.timeout,\n                )\n            finally:\n                if wrote_body_file is not None:\n                    try:\n                        await self.backend.delete_path(wrote_body_file)\n                    except Exception:\n                        pass\n\n            if result.exit_code != 0:\n                raise RuntimeError(\n                    f\"gateway shim exited with {result.exit_code}: \"\n                    f\"{result.stderr.decode(errors='replace')[:500]}\",\n                )\n\n            try:\n                env = json.loads(result.stdout)\n            except Exception as e:\n                raise RuntimeError(\n                    \"gateway shim produced non-JSON stdout: \"\n                    f\"{result.stdout[:200]!r}\",\n                ) from e\n\n            status = int(env[\"status\"])\n            if status == -1:\n                raise RuntimeError(\n                    \"gateway request failed: \"\n                    f\"{env.get('error', 'unknown error')}\",\n                )","sourceCodeStart":652,"sourceCodeEnd":688,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/workspace/_gateway_client.py#L652-L688","documentation":"Raised by GatewayClient.exec_request() when the `python3 -c SHIM_SCRIPT ...` process executed inside the sandbox exits non-zero. The shim is the tiny Python HTTP relay that runs in the sandbox and talks to 127.0.0.1:gateway_port; its stderr (first 500 chars) is included. This means the relay itself crashed before/while making the request — not that the gateway returned an error status.","triggerScenarios":"Any gateway call (connect/close/list tools/health/list_mcps/tool invocation) when the sandbox lacks python3, the shim script hits an unhandled exception (bad URL encoding, missing module), exec times out (exit code reflects timeout, stderr 'timed out'), or the sandbox killed the process (OOM).","commonSituations":"Minimal container images without python3; sandbox image updated and python3 removed/moved; oversized or malformed body causing shim exception; exec timeout too small on slow sandboxes; OOM-killed shim on very large tool payloads.","solutions":["Check the embedded stderr text — it names the actual Python traceback reason","Verify `python3` exists inside the sandbox: `await backend.exec_shell([\"python3\", \"--version\"])`","Increase GatewayClient timeout if stderr says 'timed out'","Reduce payload size or raise inline_limit if the failure correlates with large bodies","Match sandbox image to a known-good version that ships python3"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"res = await backend.exec_shell([\"python3\", \"-c\", \"print('ok')\"])\nif not res.ok():\n    raise RuntimeError(f\"sandbox lacks python3: {res.stderr[:200]!r}\")","typeGuard":null,"tryCatchPattern":"try:\n    status, body = await gateway.exec_request(...)\nexcept RuntimeError as e:\n    if \"gateway shim exited\" in str(e):\n        # shim-level crash: surface stderr, degrade gracefully\n        return None\n    raise","preventionTips":["Verify python3 exists in the sandbox image before creating GatewayClient","Pin a sandbox image known to include python3","Set an adequate timeout for slow sandboxes","Cap payload sizes to avoid shim OOM"],"tags":["gateway","shim","sandbox","python3","exec"],"backgroundTag":"sandbox-shim-crash","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}