v0.7.0

Script Runtime

Last updated


How each language wrapper receives input, runs user code, and prints the result.

Input Injection


The handler writes {"code": ..., "input": ...} as JSON to the wrapper's stdin. The wrapper parses the input string as JSON and exposes it through two globals:
GlobalContent
eventThe parsed input; {} when input is empty
inputThe same object as event

When input is not valid JSON, the wrapper writes to stderr and exits with code 1.

Per-language Behavior


LanguageRuntimeExecutionResult Output
Pythonpython3 -uIndents the code into __user_main__() so top-level return worksPrints json.dumps(return value) to stdout; prints nothing if not serializable
JavaScriptnodeWraps the code in an async function and runs it with vm.Script in the global context; await worksPrints JSON.stringify of the return value when it is not undefined
TypeScripttsxTranspiles with esbuild.transformSync (loader: ts, format: cjs, target: node18), then runs like JavaScriptPrints JSON.stringify of the top-level return value or global result

Examples


  1. total = sum(event["items"])
  2. print("summing", len(event["items"]))
  3. return {"total": total}

  1. const res = await Promise.resolve(event.a * 2);
  2. return { doubled: res };

  1. interface User { name: string; age: number }
  2. const adults = (event.users as User[]).filter(u => u.age >= 18);
  3. return adults.map(u => u.name);

Intermediate print / console.log output is ignored in non-stream mode (only the last valid JSON line counts) and becomes log events in stream mode.

Error Handling


  • Exceptions are written to stderr (Error: ...) and the wrapper exits with code 1.
  • Non-stream mode: HTTP 500 with failed to run: <error>.
  • Stream mode: any stderr output kills the process immediately and emits an error event; warnings that third-party packages print to stderr trigger it too.


中文