Code Node: Ruby, Go and Bash
The Code node runs JavaScript by default. It can also run Ruby, Go or Bash. JavaScript runs inside the workflow engine in an isolated JavaScript engine. Ruby, Go and Bash have no such language-level sandbox, so every run of one of them gets its own throwaway sandbox: a fresh container with the toolchain installed, no network access, and nothing of the workflow engine or of other runs in it. The sandbox is deleted as soon as the run ends.
These runtimes are turned on per workspace. In a workspace where they are off, a Ruby, Go or Bash Code node saves, the definition check warns about it (runtime.codeRuntimeUnavailable), and the node fails when it runs with "The Ruby runtime of the Code node is not enabled for this workspace". Ask support to turn them on.
What the script gets
| Ruby | Go | Bash | |
|---|---|---|---|
| Toolchain | Ruby with its standard library | Go with its standard library; the code is one main.go, built with go run | Bash with jq and curl |
| Packages | Standard library only | Standard library only; no module downloads | The tools in the image only |
- Input: the file at
$FG_INPUT_PATHholds one JSON document,{ "input": ..., "items": [...], "context": { "runId", "workflowKey", "version", "workspaceId", "nodeId", "triggeredAt" } }.inputis the previous node's output;itemsis itsitemsarray, or the output itself as the only item. - Output: write one JSON document to
$FG_OUTPUT_PATH. If you write no file, the last non-empty line the script prints is parsed as JSON. If that is not JSON either, the node's output is{ "stdout", "stderr", "exitCode" }. An output that is not an object is wrapped as{ "result": ... }. The output file may be at most 1 MiB. - Logs: every line the script prints becomes an author log of the node: stdout lines as info, stderr lines as errors (up to 100 lines).
- Failure: a non-zero exit fails the node with "Ruby execution failed: exit 3: ..." and the end of stderr. A run that is still going when its timeout passes is stopped, and the node fails.
- Timeout: the node's Timeout (ms) field, from 1 to 120 seconds (30 seconds when empty). It covers the script itself; starting the sandbox is not counted.
- Environment: the script starts with a clean environment: only
HOME,TMPDIR,PATH,LANG, the Go settings and theFG_*variables (FG_INPUT_PATH,FG_OUTPUT_PATH,FG_RUNTIME). Nothing from your connections or the workflow engine is passed in. Use the previous node's output to pass values in.
Because a Ruby, Go or Bash Code node starts a sandbox, it counts as a node that leaves the workflow: your workspace's action policies judge it, the same as an HTTP Request node. Its sandbox time counts against the workspace's sandbox runtime hours.
Examples
Each example reads { "value": 21 } from the previous node and returns { "doubled": 42 }.
Ruby
require "json"
data = JSON.parse(File.read(ENV.fetch("FG_INPUT_PATH")))
result = { doubled: data["input"]["value"] * 2 }
File.write(ENV.fetch("FG_OUTPUT_PATH"), JSON.generate(result))
Go
package main
import (
"encoding/json"
"fmt"
"os"
)
func main() {
raw, err := os.ReadFile(os.Getenv("FG_INPUT_PATH"))
if err != nil {
panic(err)
}
var doc struct {
Input struct {
Value int `json:"value"`
} `json:"input"`
}
if err := json.Unmarshal(raw, &doc); err != nil {
panic(err)
}
out, _ := json.Marshal(map[string]int{"doubled": doc.Input.Value * 2})
// The last line printed is the output when no output file is written.
fmt.Println(string(out))
}
Bash
set -euo pipefail
value=$(jq -r '.input.value' "$FG_INPUT_PATH")
jq -n --argjson v "$value" '{doubled: ($v * 2)}' > "$FG_OUTPUT_PATH"
Limits
- One sandbox per run, so a Ruby, Go or Bash Code node takes a few seconds longer to start than a JavaScript one. Go programs are compiled on each run; the standard library is pre-built, so a small program builds in about a second.
- No network access at all: calls to APIs belong in an HTTP Request node or an integration node before or after the Code node.
- The workspace can have up to five of these runs going at once. A run started while all of them are busy fails with a "try again shortly" error, which the node's retry settings can retry.