{"record":{"id":"29b349ec53ced8db","repo":"agentscope-ai/agentscope","slug":"gateway-shim-produced-non-json-stdout-result-std","errorCode":null,"errorMessage":"gateway shim produced non-JSON stdout: {result.stdout[:200]!r}","messagePattern":"gateway shim produced non-JSON stdout: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"src/agentscope/workspace/_gateway_client.py","lineNumber":678,"sourceCode":"                    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                )\n\n            if \"body_file\" in env:\n                spilled = env[\"body_file\"]\n                body_bytes = await self.backend.read_file(spilled)\n                try:\n                    await self.backend.delete_path(spilled)\n                except Exception:\n                    pass","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/workspace/_gateway_client.py#L660-L696","documentation":"Raised by GatewayClient.exec_request() when the in-sandbox shim exits 0 but its stdout is not parseable JSON. The shim is expected to print exactly one JSON envelope ({status, body/body_file, ...}); anything else (empty stdout, warnings printed to stdout, partial output) triggers this. The first 200 bytes of stdout are shown repr-escaped for diagnosis.","triggerScenarios":"Any gateway call where the shim's stdout is empty (killed mid-print), where the sandbox merges stderr into stdout (site warnings, deprecation notices), or where a different process/echo interferes with the exec stream.","commonSituations":"Sandbox TTY/exec config merging stderr into stdout; PYTHONWARNINGS or import-time warnings printed to stdout; shim killed by signal producing truncated stdout; version skew between SHIM_SCRIPT and what the sandbox's python3 supports.","solutions":["Inspect the repr'd stdout prefix in the message — warnings or partial JSON reveal the cause","Ensure the backend's exec captures stdout/stderr as separate streams (no TTY merging)","Set PYTHONWARNINGS=ignore / -W ignore for the sandbox python if warnings leak to stdout","Redeploy so SHIM_SCRIPT and sandbox python3 versions match"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"res = await backend.exec_shell([\"python3\", \"-c\", \"import json;print(json.dumps({'ok':1}))\"])\nif not res.ok() or not res.stdout.strip().startswith(b\"{\"):\n    raise RuntimeError(\"sandbox python stdout is polluted\")","typeGuard":null,"tryCatchPattern":"try:\n    status, body = await gateway.exec_request(...)\nexcept RuntimeError as e:\n    if \"non-JSON stdout\" in str(e):\n        logger.error(\"shim stdout polluted; inspect backend exec stream config\")\n    raise","preventionTips":["Keep exec stdout/stderr as separate streams (no TTY)","Set PYTHONWARNINGS=ignore in the sandbox environment","Version-lock the client library and sandbox image"],"tags":["gateway","shim","json","stdout","sandbox"],"backgroundTag":"sandbox-shim-crash","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}