API for running user defined python functions.
- Docker
Run the following command to build the docker image locally:
docker build -t safe-app .
Run the following docker command to start the api in a safe-ish (still has network access) environment
docker run -it --rm --readonly --cpus 1.0 --mem 512m -p 8000:8000 safe-app
Here is an example of how to use the API to register a function:
curl -X POST -H "Content-Type: application/json" \
-d '{"name": "user_func", "code": "def user_func(x):\n\treturn x + 1"}' \
http://localhost:8000/api/register-function
And then to call the function, you can run the following:
curl -X POST -H "Content-Type: application/json" \
-d '{"name": "user_func", "args": [4]}' \
http://localhost:8000/api/execute-function