feat(workflow): Add a new node for executing code

This commit is contained in:
Eternity
2026-01-26 17:29:44 +08:00
parent 3b4b474ce8
commit f1f887faae
8 changed files with 193 additions and 11 deletions

View File

@@ -15,7 +15,6 @@ class ExecutionResult:
self.stdout = stdout
self.stderr = stderr
self.exit_code = exit_code
self.error = error
class CodeExecutor(ABC):

View File

@@ -9,12 +9,15 @@ from app.config import SANDBOX_USER_ID, SANDBOX_GROUP_ID, get_config
from app.core.encryption import generate_key, encrypt_code
from app.core.executor import CodeExecutor, ExecutionResult
from app.core.runners.python.settings import check_lib_avaiable, release_lib_binary, LIB_PATH
from app.logger import get_logger
from app.models import RunnerOptions
# Python sandbox prescript template
with open("app/core/runners/python/prescript.py") as f:
PYTHON_PRESCRIPT = f.read()
logger = get_logger()
class PythonRunner(CodeExecutor):
"""Python code runner with security isolation"""
@@ -106,6 +109,7 @@ class PythonRunner(CodeExecutor):
env["ALLOWED_SYSCALLS"] = ",".join(map(str, config.allowed_syscalls))
# Execute with Python interpreter
logger.info(encoded_key)
process = await asyncio.create_subprocess_exec(
config.python_path,
@@ -143,7 +147,6 @@ class PythonRunner(CodeExecutor):
stdout="",
stderr="Execution timeout",
exit_code=-1,
error="Execution timeout"
)
finally:

View File

@@ -37,8 +37,8 @@ async def run_python_code(code: str, preload: str, options: RunnerOptions):
if result.exit_code == -signal.SIGSYS:
return error_response(31, "sandbox security policy violation")
if result.error:
return error_response(-500, result.error)
if result.stderr:
return error_response(500, result.stderr)
return success_response(RunCodeResponse(
stdout=result.stdout,