go-faas - Documentation

July 13, 2026 · View on GitHub

Back to README

Prerequisites

  • Go 1.23 or higher
  • Linux (Ubuntu, Debian, Fedora, Arch Linux, Alpine Linux; production sandbox targets Linux)
  • Redis server
  • Bubblewrap (bwrap)
  • Node.js (with npm) and TypeScript runtime (tsx)
  • Python 3
  • systemd (for slice resource control)

Installation

From Source

git clone https://github.com/pardnchiu/go-faas.git
cd go-faas
go build -o go-faas cmd/api/main.go

Using go install

go install github.com/pardnchiu/go-faas/cmd/api@latest

Install TypeScript Dependencies

npm install

On first launch, the program checks for bwrap, node, and python3. If any are missing, it attempts to install them via the system package manager.

Configuration

Environment Variables

Copy .env.example and fill in the values:

cp .env.example .env
VariableRequiredDefaultDescription
HTTP_PORTNo8080HTTP server port
MAX_CPUSNo1Sandbox CPU quota (cores)
MAX_MEMORYNo128MSandbox memory ceiling
CODE_MAX_SIZENo262144 (256KB)Maximum allowed code size in bytes
TIMEOUT_SCRIPTNo30Script execution timeout in seconds
REDIS_HOSTNolocalhostRedis host address
REDIS_PORTNo6379Redis port
REDIS_PASSWORDNoemptyRedis password
REDIS_DBNo0Redis database number
REDIS_TIMEOUT_SECONDSNo5Redis connection timeout in seconds

Usage

Start the Server

./go-faas

Basic: Upload a Script

Store a script in Redis and receive a version number:

curl -X POST http://localhost:8080/upload \
  -H "Content-Type: application/json" \
  -d '{
    "path": "math/add",
    "language": "python",
    "code": "return event.get(\"a\", 0) + event.get(\"b\", 0)"
  }'

Response:

{
  "path": "math/add",
  "language": "python",
  "version": 1739000000
}

Basic: Execute a Stored Script

Run the latest version by path:

curl -X POST http://localhost:8080/run/math/add \
  -H "Content-Type: application/json" \
  -d '{
    "input": "{\"a\": 3, \"b\": 5}"
  }'

Run a specific version:

curl -X POST "http://localhost:8080/run/math/add?version=1739000000" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "{\"a\": 3, \"b\": 5}"
  }'

Response:

{
  "data": 8,
  "type": "number"
}

Advanced: Execute Code Immediately

Submit code for direct execution without storing:

curl -X POST http://localhost:8080/run-now \
  -H "Content-Type: application/json" \
  -d '{
    "language": "javascript",
    "code": "return { sum: event.a + event.b }",
    "input": "{\"a\": 10, \"b\": 20}"
  }'

Response:

{
  "data": { "sum": 30 },
  "type": "json"
}

Advanced: SSE Streaming Mode

Set stream: true to enable Server-Sent Events streaming output:

curl -X POST http://localhost:8080/run-now \
  -H "Content-Type: application/json" \
  -d '{
    "language": "python",
    "code": "import time\nfor i in range(5):\n    print(i)\n    time.sleep(0.5)\nreturn \"done\"",
    "input": "{}",
    "stream": true
  }'

Streaming response format:

data: {"event":"log","data":"0","type":"text"}

data: {"event":"log","data":"1","type":"text"}

data: {"event":"result","data":"done","type":"string"}

API Reference

Endpoints

MethodPathDescription
POST/uploadUpload a script to Redis
POST/run/*targetPathExecute a stored script
POST/run-nowExecute submitted code immediately

POST /upload

Upload and store a script in Redis, returning a version number.

Request Body:

FieldTypeRequiredDescription
pathstringYesScript access path (must not contain ..)
codestringYesCode content
languagestringYesLanguage (python, javascript, typescript)

Response:

{
  "path": "string",
  "language": "string",
  "version": 1739000000
}

POST /run/*targetPath

Fetch a script from Redis and execute it inside the sandbox.

Query Parameters:

ParameterTypeRequiredDescription
versionint64NoTarget version number; defaults to latest

Request Body:

FieldTypeRequiredDescription
inputstringNoJSON-formatted input data, accessible as event in the script
streamboolNoEnable SSE streaming output

POST /run-now

Submit code for direct sandbox execution without Redis storage.

Request Body:

FieldTypeRequiredDescription
codestringYesCode content
languagestringYesLanguage (python, javascript, typescript)
inputstringNoJSON-formatted input data
streamboolNoEnable SSE streaming output

Response Format

Standard responses auto-detect the return data type:

typeDescription
stringString value
numberNumeric value
jsonJSON object or array
textPlain text (not valid JSON)

SSE Event Format

eventDescription
logIntermediate script output (print / console.log)
resultFinal execution result
errorExecution error message

Supported Languages

LanguageRuntimeExtensionGlobal Variables Available in Script
Pythonpython3.pyevent, input
JavaScriptnode.jsevent, input
TypeScripttsx.tsevent, input

©️ 2025 邱敬幃 Pardn Chiu