Code Monkey home page Code Monkey logo

codex-api's Introduction

CodeX API

This API is still in very early stages of development. So consider not using the API in production since things might change in the future.

Introducing the new CodeX API

Here's how you can execute code in various languages on your own website for free (no, there's no fucking catch, it's literally free),

Execute Code and fetch output

POST /

This endpoint allows you to execute your script and fetch output results.

What are the Input Parameters for execute api call?

Parameter Description
"code" Should contain the script that needs to be executed
"language" Language that the script is written in for example: java, cpp, etc. (Check language as a payload down below in next question)
"input" In case the script requires any kind of input for execution, leave empty if no input required

What are the languages that are supported for execution?

Whichever language you might mention in the language field, it would be automatically executed with the latest version of it's compiler.

Languages Language as a payload
Java java
Python py
C++ cpp
C c
GoLang go
C# cs
NodeJS js

More coming very soon!

NodeJS Example to Execute API Call?

var axios = require('axios');
var qs = require('qs');
var data = qs.stringify({
    'code': 'val = int(input("Enter your value: ")) + 5\nprint(val)',
    'language': 'py',
    'input': '7'
});
var config = {
    method: 'post',
    url: 'https://api.codex.jaagrav.in',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    data : data
};

axios(config)
  .then(function (response) {
    console.log(JSON.stringify(response.data));
  })
  .catch(function (error) {
    console.log(error);
  });

Sample Output

The output is a JSON object comprising only one parameter that is the output.

{
  "timeStamp": 1672439982964,
  "status": 200,
  "output": "Enter your value: 12\n",
  "error": "",
  "language": "py",
  "info": "Python 3.6.9\n"
}

Since a lot of people had issues with executing the previous API from backend or serverless function, unlike the previous version of the API, this version of the API won't throw any Cross Origin errors so you can use this from the front end without any worries. Thank me later ;)

GET /list

This endpoint allows you to list all languages supported and their versions.

{
  "timeStamp": 1672440064864,
  "status": 200,
  "supportedLanguages": [
    {
      "language": "java",
      "info": "openjdk 11.0.17 2022-10-18\nOpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu218.04)\nOpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu218.04, mixed mode, sharing)\n"
    },
    {
      "language": "cpp",
      "info": "g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0\nCopyright (C) 2017 Free Software Foundation, Inc.\nThis is free software; see the source for copying conditions.  There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
    },
    {
      "language": "py",
      "info": "Python 3.6.9\n"
    },
    {
      "language": "c",
      "info": "gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0\nCopyright (C) 2017 Free Software Foundation, Inc.\nThis is free software; see the source for copying conditions.  There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
    },
    {
      "language": "js",
      "info": "v16.13.2\n"
    },
    {
      "language": "go",
      "info": "go version go1.10.4 linux/amd64\n"
    },
    {
      "language": "cs",
      "info": "Mono C# compiler version 4.6.2.0\n"
    }
  ]
}

This API is deployed on a free instance on render so shoutout to render for providing a platform that helped bringing back the CodeX API after a long down time. Since I am using a free tier, the API might be slow sometimes, so please be patient while I try to fund this project.

Happy hacking!

codex-api's People

Contributors

akira-cn avatar codersk avatar jaagrav avatar yasserdbeis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

codex-api's Issues

Python code compilation error

Encountering error during compilation of code with more than one input. Here is the code:
a = input()
b = input()
print(a, b)

And here is the compilation message:

Traceback (most recent call last):
File "/app/codes/63db007e-7ed3-473e-abe9-d5a0e2c95fa8.py", line 2, in
b = input()
EOFError: EOF when reading a line

Can’t use api

I’m getting an 405 error every time. “Method not allowed” and I’m using POST method

API has crashed

When I try to compile code, I get the Heroku Application error.
image

[Security Vulnerability] Allowing malicious code injection.

I have identified a security vulnerability in the CodeX-API repository. The vulnerability allows an attacker to inject malicious code into the server, which can potentially harm the server and allow unauthorized access to sensitive information. Specifically, an attacker is able to delete files on the server using javascript or other programming language.

This security vulnerability poses a significant threat to the project's integrity and the security of the data stored in the server.

C language seems to be using a cpp compiler?

When I try to compile my C code using the CodeX C compiler, i get a lot of errors complaining about casting a void* to something else, which is fine in C however forbidden in CPP (source: https://stackoverflow.com/a/22744183/11804669)

Which is really weird because that would mean the C language for CodeX is actually compiled as if it was C++

So as a test I tried copy pasting a C++ Hello World script into it (which should not AT ALL) compile if it was really C

and that worked

Implementation in Java

private JSONObject getCompileResult(String code, String input, String language) throws UnirestException { Unirest.setTimeouts(0, 0); HttpResponse<String> response = Unirest.post("https://codex-api.herokuapp.com") .header("Content-Type", "application/x-www-form-urlencoded") .field("code", code) .field("language", language) .field("input", input==null ? "" : input) .asString(); return new JSONObject(response.getBody()); }

[Enhancement] Repetitive Code to Run/Execute Each Language

Creating this as an issue to be tackled in a future PR.

Just noticed that the code to run/execute each language is basically the same, minus the spawn command. Thought the code could be refactored to avoid such redudancy.

I will likely pick this issue up if someone does not already in the upcoming day(s).

discontinued?

is this discontinued cuz its says that the service has been suspended

impossibility to use pointers or anything that needs the adress of a variable in c

its impossible to do so cause if we use the & character it just doesnt work and it ends the code at that points ( probably because after the & after the code is expecting the language ), so, its basicly impossible to do anything in C, am i just being dumb or is it really a bug?

(( without the scanf(\"%i\", &ia); part and the input=10 part the code works but i really need the input part for what im doing ))

"code=#include<stdio.h>\nint main(){\nprintf("meow");\nint ia = 0;\nscanf("%i", &ia);\n printf("%i", ia);\n\n}\n&language=c&input=10"

image

Api stopped working

its giving a 500 server response :(. Please get it up again, its really really useful, thanks

Heroku Issue

As Heroku has closed its free tiers the API is down. Please host it on sites like railway or porter so that the API can be up again. Thank you for the amazing API.

How do I get stdin input with javascript?

const input = require('fs').readFileSync('/dev/stdin').toString().split(' ');
console.log(Number(input[0]) + Number(input[1]));

With this code, I get error
"node:internal/fs/utils:344\n throw err;\n ^\n\nError: ENXIO: no such device or address, open '/dev/stdin'\n at Object.openSync (node:fs:585:3)\n at Object.readFileSync (node:fs:453:35)\n at Object. (/app/codes/10609b19-df6a-4e33-8cc6-f31183eb3f29.js:1:29)\n at Module._compile (node:internal/modules/cjs/loader:1101:14)\n at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)\n at Module.load (node:internal/modules/cjs/loader:981:32)\n at Function.Module._load (node:internal/modules/cjs/loader:822:12)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n at node:internal/main/run_main_module:17:47 {\n errno: -6,\n syscall: 'open',\n code: 'ENXIO',\n path: '/dev/stdin'\n}\n"

How can i access to stdin in javascript?

Issue with API

api is not working properly getting response like -->

code:"ENOENT"
errno:2
path:"/app/codes/4cfb0f33-3ec6-464e-8eed-be734ed1ab41.py"
status:500
syscall:"open"
timeStamp:1685425605602

API has crashed

Getting the following response

response: {
status: 503,
statusText: 'Service Unavailable',
headers: {
connection: 'close',
server: 'Cowboy',
date: 'Sun, 30 Oct 2022 07:40:57 GMT',
'content-length': '506',
'content-type': 'text/html; charset=utf-8',
'cache-control': 'no-cache, no-store'
},

Working with multiple input

Is there a way to work with multiple input? For example the code is java, and asking twice for getting input from users.

Internal server error

While i was testing API call through postman extension in vs code i got this error ...
image

[Enhancement] Add compilation/running of multiple files

Future feature to be implemented: running code with multiple files.

This seems fairly straight forward with compiled languages. For example, for c/cpp we can send the code as an array of strings, have the file for each code string created, and the g++ command should take care of the rest in creating the executable. Some minor accomodations may need to be made to differentiate b/w header and non-header files, but that is not a big deal.

For interpreted languages, like python, I am not sure its as straight forward with the current mechanism. This is because if a python file imports from a file called "x", the imported filename will be modified to a UUID with the current set-up and thus the import statement will be broken. However, I might be misunderstanding and welcome criticism/solutions.

Java code not working

I cloned this project, run rpm install. Everything seems to working fine. I tested c, cpp, js codes, all work fine but java code is not working.

case 'java':
            return {
                executeCodeCommand: 'java',
                executionArgs: [
                    join(process.cwd(), `codes/${jobID}.java`)
                ],
                compilerInfoCommand: 'java --version'
            };

Api Stopped working

Api has stopped working we're not able to use it anymore
Isuues:
{
"timeStamp": 1707629578253,
"status": 500,
"errno": -2,
"syscall": "open",
"code": "ENOENT",
"path": "/app/codes/c1e8d4c9-d328-438a-a450-dfbde74f4681.java"
}
it shows errorcode:500
please fix it

Remote code execution

Hey I was actually analyzing the Codex API (which by the way is actually superb). While doing so one thing crossed my mind can I run this:

const testFolder = './';
const fs = require('fs');

fs.readdir(testFolder, (err, files) => {
  files.forEach(file => {
    console.log(file);
  });
});

I am not exactly about testFolder path, but I did put in something. When I executed the script it did give me the list of the contents (files & folders) in that directory. Now do the following:

// Instead of console.log(file); do
fs.unlinkSync(file)

I have a temporary solution for this too, using node >=20 with Experimental Permission Model. It also helps us decide where we can run exec. But this solution is not great, May be we have to first analyze the code making sure it is not accessing something it should not. Then go ahead and use some proper Linux resource permission etc.

It I get around will link a pull request.

Thanks
Anweshan ([email protected])
Office: [email protected]

API is crashed

I written a program in C++ for infinite memory usage which is as follows

#include<iostream>
using namespace std;

int main() {
    while(true) {
        int *n = new int[10000];
    }
}

I think the API has been crashed after executing above code as it is showing 'Network Error' now (earlier it was working fine). please try to resolve this issue and place a limit on memory usage and execution time.

Deploy in another platform

As from 28th Nov 2022 Heroku going to charge money for free dynos ,so I am saying you to host it another platform to get free api hosting service. Thank you!!

Installation takes a long time

Installation takes a long time. Docker Build is stuck at stage 7/15.
GET 371 ubuntu npm.
The package has been downloaded a million times already. I've been waiting for more than 10 hours. I tried again, but the result did not change. Here is a screenshot
System: Centos 7, docker is latest version.
image

Delayed asynchronous code features

Is there a way to work with asynchronous code that have delay? For example, setTimeout() in javascript.

If i made a code inside the timeout and make the delay to be 2 seconds, all of the code just executed. Here is example code

console.log("before timeout");
setTimeout(() => {
    console.log("inside timeout");
}, 2000);

How to use this API

Hi,

You have done great work. Can I know, How to use CodeX Api.

Thank You!

Issue with API

API having issue right now

POST is not working

image

{
    "timeStamp": 1688111559630,
    "status": 500,
    "errno": -2,
    "syscall": "open",
    "code": "ENOENT",
    "path": "/app/codes/ae816f83-a965-42bf-8378-732ad5ddda98.java"
}


get is working well

i remember the last time.
same issue started before actually shutting down all functions.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.