The Code Execution Sandbox API provides endpoints for executing code in various programming languages within secure Docker containers.
- Development:
http://localhost:5000/api - Production:
https://your-domain.com/api
GET /api/health
Returns the health status of the API server.
Response:
{
"status": "healthy",
"timestamp": "2024-01-01T00:00:00.000Z",
"uptime": 3600,
"memory": {
"rss": 50000000,
"heapTotal": 20000000,
"heapUsed": 15000000
},
"supportedLanguages": ["python", "javascript"]
}POST /api/execute
Executes code in the specified programming language.
Request Body:
{
"code": "print('Hello, World!')",
"language": "python"
}Response (Success):
{
"success": true,
"message": "Code executed successfully",
"result": "Hello, World!",
"metadata": {
"language": "python",
"codeLength": 23,
"timestamp": "2024-01-01T00:00:00.000Z"
}
}Response (Error):
{
"error": "Code is required and must be a non-empty string",
"received": {
"code": null,
"language": "python"
}
}POST /api/cleanup
Manually triggers cleanup of temporary files.
Response:
{
"message": "Cleanup initiated",
"timestamp": "2024-01-01T00:00:00.000Z"
}- Python (
pythonorpy) - JavaScript (
javascriptorjs)
400- Bad Request (invalid input, unsupported language)500- Internal Server Error (execution failure, system error)
Currently no rate limiting is implemented, but it's recommended for production deployments.
- Code execution is sandboxed in Docker containers
- Containers are destroyed after each execution
- Network access is disabled in execution containers
- Memory and CPU limits are enforced