This project aims to create a containerized environment for executing code snippets. It provides a secure and isolated environment for running code, making it suitable for online coding platforms, code editors, and other similar applications.
- Containerized execution environment
- Support for multiple programming languages
- Secure sandboxing to prevent unauthorized access
- Resource limitations to prevent abuse
- Easy integration with existing applications
To install and run the CodeExecContainer, follow these steps:
-
Clone the repository:
git clone https://github.com/your-username/CodeExecContainer.git
-
Navigate to the project directory:
cd CodeExecContainer
-
Install the dependencies:
pip install -r requirements.txt
-
Start the application:
source run.sh --port 5097
To use the CodeExecContainer, follow these steps:
-
Make a POST request to the
/execute
endpoint with the following parameters:code
: The code snippet to be executed.lang
: The programming language of the code snippet.version
: The version of the programming language (optional).stdin
: The standard input for the code snippet (optional).timeout
: The maximum execution time for the code snippet in seconds (optional).memory_limit
: The maximum memory usage for the code snippet in bytes (optional).cpu_limit
: The maximum CPU usage for the code snippet in seconds (optional).
Example using cURL:
curl -X POST -H "Content-Type: application/json" \ -d '{"code": "print(\"Hello, World!\")", "lang": "python"}' \ http://localhost:5097/execute
-
The response will contain the output of the executed code.
Example response:
{ "output": "Hello, World!\n" }
-
If an error occurs during execution, the response will contain an error message.
Example error response: ```json { "error": "Execution failed: TimeoutError: Execution timed out", } ```
Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.