We're Riza, and we make running untrusted code safe and easy. Starting today you can send us a Python, JavaScript or TypeScript function body for execution, rather than a whole script.
When we launched the Riza Code Interpreter API as a developer preview last year it had just one endpoint allowing you to send us a script for execution. Since then we've added several new endpoints to customize the Riza runtime, manage secrets, and even store and run code as "tools." But the primary endpoint for executing code hasn't changed.
A script that interacts with stdin
and stdout
is simple for prototyping, but it's clunky
when you want to write code that operates on structured inputs and outputs. So we've added a new
Execute Function endpoint to
the Riza Code Interpreter API that lets you send us a function body for
execution.
How it works
To use the Execute Function endpoint you send a function named execute
that accepts a single
input parameter and returns any JSON-serializable value. Here's an example in Python:
def execute(input):
greeting = f"Hello, {input['name']}"
return {"greeting": greeting}
Pass this function body along with any input data to the Execute Function endpoint:
curl https://api.riza.io/v1/execute-function \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RIZA_API_KEY" \
--data-binary @- << EOF
{
"language": "python",
"code": "def execute(input):\n greeting = f\"Hello, {input['name']}\"\n return {\"greeting\": greeting}",
"input": {"name": "Andrew"}
}
EOF
Riza executes the function with the given input, serializes the return value as JSON and responds with the result:
{
"execution": {
"exit_code": 0,
"stderr": "",
"stdout": ""
},
"output_status": "valid",
"output": {
"greeting": "Hello, Andrew"
}
}
Wrapping up
We know this will make integration easier for lots of interesting use cases, and we're excited to see what you'll build! As always, we'll be available in Discord or via email to answer questions and take feedback.
And if you're looking for something else to read, check out this post about Just-in-time Programming with Riza.