Skip to content

It is a web-based Python interpreter that leverages nsjail to isolate each user session securely and uniquely. The application uses FastAPI for the backend and Monaco Editor for the frontend.

Notifications You must be signed in to change notification settings

nebulaanish/code_editor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Code Editor

A web-based Python code editor with real-time execution capabilities, built with Next.js and FastAPI.

Features

  • Real-time code editing with Monaco Editor
  • Python code execution with secure sandboxing using nsjail
    • Each user's code runs in an isolated environment
    • Prevents interference between different users' code
    • Ensures system security and resource isolation
  • Syntax highlighting and code suggestions
  • Auto-indentation and bracket matching
  • Terminal output display
  • Docker support for easy deployment

Limitations

  • Resource Constraints: The sandbox environment has limited resources (CPU, memory) to prevent abuse
  • System Access: Restricted access to system files and network to maintain security

Quick Start with Docker Compose

The easiest way to run the application is using Docker Compose:

  1. Clone the repository:
git clone <repository-url>
cd code_editor
  1. Set up environment variables:
# For backend
cp backend/.env.example backend/.env
# For frontend
cp frontend/.env.example frontend/.env
  1. Edit the .env files with your desired values:
  • Backend: Configure sandbox settings and server parameters
  • Frontend: Set the API URL and other frontend-specific variables
  1. Build and start the services:
docker compose up --build
  1. Access the application:
  1. To stop the services:
docker compose down

Manual Setup

Backend Setup

  1. Navigate to the backend directory:
cd backend
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your desired values
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Start the backend server:
uvicorn main:app --reload --host 0.0.0.0 --port 8000

The backend API will be available at http://localhost:8000

Frontend Setup

  1. Navigate to the frontend directory:
cd frontend
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your desired values
  1. Install dependencies:
npm install
  1. Start the development server:
npm run dev

The frontend will be available at http://localhost:3000

Development

Backend Development

  • The backend is built with FastAPI
  • Main application file: backend/main.py
  • API routes are defined in backend/src/app.py
  • Environment variables can be set in .env file

Frontend Development

  • The frontend is built with Next.js
  • Main components are in frontend/components/
  • Pages are in frontend/app/
  • Styling uses Tailwind CSS

About

It is a web-based Python interpreter that leverages nsjail to isolate each user session securely and uniquely. The application uses FastAPI for the backend and Monaco Editor for the frontend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published