A simple way to run Free Pascal programs in the browser so new developers can learn the language without having to install anything.
Give it a try here: FPC Playground
Warning
This project is still a work in progress and will not support all Free Pascal features.
- π FPC Playground
- Web-based Pascal editor with syntax highlighting
- Real-time compilation and execution
- Program arguments support - Pass command line arguments to your Pascal programs
- User input support - Handle
ReadLn()
statements with dedicated input fields - Example programs to get started quickly
- Security filtering to prevent dangerous operations
- Educational-friendly interface with clear separation of code, input, and output
- Smart Keyword Detection: Advanced pattern matching prevents dangerous operations while allowing legitimate code
- Multi-layered Validation: Character encoding, complexity checks, and comprehensive threat detection
- Word Boundary Matching: Uses regex word boundaries (
\b
) for precise keyword detection - Context-Aware Shell Detection: Shell commands only blocked in dangerous contexts (e.g.,
sh -c
,/bin/sh
) - Educational Focus: Secure enough for learning environments, flexible enough for creativity
Make sure you have Docker installed. You can download it from Docker's official site.
- Clone the repository:
git clone https://github.com/ikelaiah/fpc-playground.git
- Run Docker Compose:
docker-compose up
- Access the frontend at
http://localhost:8080
and start coding!
We value your feedback! If you enjoy using FPC Playground, please star the repository and share your thoughts.
To simplify setup, you can use Docker Compose to run both the backend and frontend services:
- Clone the repository:
git clone https://github.com/ikelaiah/fpc-playground.git
- Navigate to the project directory:
cd fpc-playground
- Run Docker Compose:
docker-compose up
- Access the frontend at
http://localhost:8080
and the backend athttp://localhost:5000
.
The FPC Playground provides an intuitive interface for learning Pascal programming:
- Write your Pascal code with syntax highlighting
- Use the example buttons to load pre-written programs
- Fix quotes automatically for Pascal compatibility
- Use the "Program Arguments" textarea to pass command line arguments to your program
- Separate multiple arguments with spaces
- Example:
arg1 arg2 arg3
- Use the "User Input" textarea to provide input for
ReadLn()
statements - Enter each input value on a separate line
- The program will read these values in order when it encounters
ReadLn()
program TestInput;
var
name: string;
age: integer;
begin
writeln('What is your name?');
readln(name);
writeln('How old are you?');
readln(age);
writeln('Hello ', name, ', you are ', age, ' years old!');
end.
For this program, enter in the User Input field:
John
25
The output will be:
What is your name?
How old are you?
Hello John, you are 25 years old!
To run the backend manually without Docker Compose, follow these steps:
- Clone the repository:
git clone https://github.com/ikelaiah/fpc-playground.git
- Navigate to the
backend
directory:
cd fpc-playground/backend
- Build the Docker image:
docker build -t fpc-playground-backend .
- Run the Docker container:
docker run -p 5000:5000 fpc-playground-backend
The frontend is a simple HTML page that interacts with the backend API using JavaScript.
To run the frontend manually, you can simply open the index.html
file in your web browser. It will automatically connect to the backend running on http://localhost:5000
.
Run the following commands to test the backend using curl
:
cd backend
docker build -t fpc-playground-backend .
docker run -p 5000:5000 fpc-playground-backend
Note: The API requires base64 encoded Pascal code, arguments, and input.
# Create test payload with base64 encoded Pascal code
echo '{"code":"'$(echo "program HelloWorld; begin writeln('Hello, World!'); end." | base64 -w 0)'","args":"","input":""}' > test.json
curl -X POST http://localhost:5000/run -H "Content-Type: application/json" -d @test.json
Alternative method using a helper script:
# Create a simple test script
cat > test_api.sh << 'EOF'
#!/bin/bash
CODE="program HelloWorld; begin writeln('Hello, World!'); end."
ENCODED_CODE=$(echo -n "$CODE" | base64 -w 0)
echo '{"code":"'$ENCODED_CODE'","args":"","input":""}' | curl -X POST http://localhost:5000/run -H "Content-Type: application/json" -d @-
EOF
chmod +x test_api.sh
./test_api.sh
- Code size: Maximum 16KB per program
- Output size: Limited to 48KB to prevent abuse
- Rate limiting: 150 requests per hour, 10 per minute
- Pascal features: Not all Free Pascal features supported (work in progress)
- Complex structures: Limited nested structures (max 20
begin
statements, 100 parentheses, 50 brackets) - Character encoding: Only standard ASCII characters (32-126) plus newlines, carriage returns, and tabs
- "Code contains restricted keyword": Check for Pascal reserved words in variable names or use different names
- "Code structure too complex": Simplify nested structures or break code into smaller functions
- Connection refused: Ensure Docker containers are running on correct ports (8080 for frontend, 5000 for backend)
- Compilation errors: Verify Pascal syntax - the playground uses Free Pascal 3.2.2+
- "Code contains invalid characters": Use only standard ASCII characters in your code
- Check our Issues page for known problems
- Join the Free Pascal Discord for community support
- Review the CHANGELOG.md for recent updates and fixes
We welcome contributions! To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes and commit them (
git commit -m "Add feature"
). - Push to your branch (
git push origin feature-branch
). - Open a pull request.
MIT License - see LICENSE file for details.
- Free Pascal Dev Team for the Pascal compiler
- Lazarus IDE Team for such an amazing IDE
- The kind and helpful individuals on various online platforms such as:
- All contributors who have helped improve this project