-
A simple project that exposes an api through (HTTP POST "/") to run js code and return console.log's in array and the value of the last executed line of code
- Sample request -
{ code: "let x = 1; console.log('hi'); x;" }
- Async function sample -
{code: " async function x() { return 1;} (async () => { return await x();})();"
} - Sample response -
{ logs: ['hi'], result: 1}
- Sample request -
-
Built using aws-cdk, typescript, nodejs, express, and isolated-vm
- Used isolated-vm to run untrusted code securely using v8:Isolate feature
- other choices were vm2, which fell short
- Used aws-cdk and typescript to replicate, deploy and scale AWS infra easily
- Used simple javascript for fast prototyping
- Used isolated-vm to run untrusted code securely using v8:Isolate feature
-
A simple ci/cd is setup using circleci to build and deploy to AWS with github checks
yarn install
yarn dev
- Send an HTTP POST to
http://localhost:3000
with a body{ code: "let x = 1; console.log('hi'); x;" }
- Important: You must be on a Linux machine to deploy this successfully because isolated-vm have native modules. Alternatively, if you setup your circleci with this project it will automatically deploy to AWS on master, but you also need to configure the env variables. Do note, setting up the right node version on the machine is also important
yarn install
yarn build:api
yarn build:cdk
- Configure your AWS environment variables
- AWS_ACCESS_KEY_ID
- AWS_SECRET_KEY
- CDK_DEPLOY_ACCOUNT
- CDK_DEFAULT_REGION
yarn cdk list
to check stacks availableyarn cdk deploy code-runner-staging