fix(sandbox): treat non-zero exit codes as errors instead of relying only on stderr
This commit is contained in:
@@ -39,7 +39,7 @@ class CodeNodeConfig(BaseNodeConfig):
|
|||||||
description="output variables"
|
description="output variables"
|
||||||
)
|
)
|
||||||
|
|
||||||
code_content: str = Field(
|
code: str = Field(
|
||||||
default="",
|
default="",
|
||||||
description="code content"
|
description="code content"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class CodeNode(BaseNode):
|
|||||||
result = {}
|
result = {}
|
||||||
for output in self.typed_config.output_variables:
|
for output in self.typed_config.output_variables:
|
||||||
value = exec_result.get(output.name)
|
value = exec_result.get(output.name)
|
||||||
if not value:
|
if value is None:
|
||||||
raise RuntimeError(f"Return value {output.name} does not exist")
|
raise RuntimeError(f"Return value {output.name} does not exist")
|
||||||
match output.type:
|
match output.type:
|
||||||
case VariableType.STRING:
|
case VariableType.STRING:
|
||||||
@@ -104,7 +104,7 @@ class CodeNode(BaseNode):
|
|||||||
"x-api-key": 'redbear-sandbox'
|
"x-api-key": 'redbear-sandbox'
|
||||||
},
|
},
|
||||||
json={
|
json={
|
||||||
"language": "python3",
|
"language": self.typed_config.language,
|
||||||
"code": base64.b64encode(final_script.encode("utf-8")).decode("utf-8"),
|
"code": base64.b64encode(final_script.encode("utf-8")).decode("utf-8"),
|
||||||
"options": {
|
"options": {
|
||||||
"enable_network": True
|
"enable_network": True
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ async def run_python_code(code: str, preload: str, options: RunnerOptions):
|
|||||||
if result.exit_code == -signal.SIGSYS:
|
if result.exit_code == -signal.SIGSYS:
|
||||||
return error_response(31, "sandbox security policy violation")
|
return error_response(31, "sandbox security policy violation")
|
||||||
|
|
||||||
if result.stderr:
|
if result.stderr and result.exit_code != 0:
|
||||||
return error_response(500, result.stderr)
|
return error_response(500, result.stderr)
|
||||||
|
|
||||||
return success_response(RunCodeResponse(
|
return success_response(RunCodeResponse(
|
||||||
|
|||||||
Reference in New Issue
Block a user