A peer-to-peer code execution application built with Electron that allows you to execute code (JavaScript and Python) on remote computers using their computing power over a direct P2P connection.
- Peer-to-Peer Connection: Direct WebRTC connection between two computers
- Remote Code Execution: Execute JavaScript and Python code on a remote peer's machine
- Local Execution: Test code locally before sending to remote peer
- Real-time Communication: Instant code execution and result retrieval
- Room-based System: Create or join rooms to connect with peers
- Cross-platform: Works on Windows, macOS, and Linux
- Distributed Computing: Utilize remote computing power for heavy computations
- Code Testing: Test code on different environments
- Collaborative Coding: Share and execute code with teammates
- Resource Sharing: Leverage powerful machines for intensive tasks
Before you begin, ensure you have the following installed:
- Node.js (v14 or higher) - Download
- Python (for Python code execution) - Download
- npm (comes with Node.js)
-
Clone or download this repository
-
Install dependencies:
npm install
This will install:
- Electron
- SimplePeer (WebRTC wrapper)
- Socket.IO (for signaling server)
- Other required dependencies
The application requires two components to run:
Open a terminal and run:
npm run serverYou should see:
Signaling server running on port 3000
Keep this terminal open! The signaling server must be running for peers to connect.
Open a new terminal and run:
npm startThis will launch the Electron application window.
Option A: Two Windows (Same Computer - For Testing)
- Open a second terminal and run
npm startagain - In Window 1: Click "Create Room"
- Copy the generated Room ID
- In Window 2: Paste the Room ID and click "Join Room"
- Wait for "Connected" status
Option B: Two Different Computers (Same Network)
-
Computer 1:
- Start signaling server:
npm run server - Start app:
npm start - Click "Create Room"
- Share the Room ID with Computer 2
- Start signaling server:
-
Computer 2:
- Start app:
npm start - Enter the Room ID from Computer 1
- Click "Join Room"
- Start app:
- Click the "Create Room" button
- A Room ID will be generated (e.g., "A3X9K2")
- Share this Room ID with the peer you want to connect with
- Wait for a peer to join
- Enter the Room ID in the input field
- Click the "Join Room" button
- Wait for connection status to show "Connected"
Local Execution:
- Write your code in the editor
- Select the language (JavaScript or Python)
- Click "Execute Locally" to run on your machine
Remote Execution:
- Ensure you're connected to a peer (status shows "Connected")
- Write your code in the editor
- Select the language
- Click "Execute on Remote Peer" to run on the remote peer's machine
- Results will appear in the Output panel
JavaScript:
const os = require('os');
console.log('Computer Name:', os.hostname());
console.log('CPU Count:', os.cpus().length);
console.log('Total Memory:', Math.round(os.totalmem() / 1024 / 1024 / 1024) + ' GB');Python:
import platform
import os
print(f"Computer Name: {platform.node()}")
print(f"OS: {platform.system()} {platform.release()}")
print(f"CPU Count: {os.cpu_count()}")electron-p2p/
βββ main.js # Electron main process
βββ renderer.js # Renderer process (UI logic)
βββ p2p-manager.js # P2P connection manager
βββ code-executor.js # Code execution engine
βββ signaling-server.js # Signaling server for WebRTC
βββ index.html # Application UI
βββ styles.css # Application styles
βββ package.json # Project dependencies
βββ README.md # This file
βββββββββββββββ βββββββββββββββ
β Peer A βββββ P2P WebRTC ββββΊβ Peer B β
β (Client) β β (Worker) β
βββββββββββββββ βββββββββββββββ
β β
β 1. Send code β
ββββββββββββββββββββββββββββββββββββΊβ
β β
β 2. Execute β
β on Peer B β
β β
β 3. Return results β
βββββββββββββββββββββββββββββββββββββ€
- Signaling Phase: Peers connect to signaling server to exchange WebRTC signals
- P2P Establishment: Direct peer-to-peer connection is established via WebRTC
- Code Execution: Code is sent over P2P connection and executed on remote peer
- Result Return: Execution results are sent back through P2P connection
- Electron: Desktop application framework
- WebRTC: Peer-to-peer communication protocol
- SimplePeer: WebRTC wrapper library
- Socket.IO: Real-time signaling server
- Node.js VM: JavaScript code execution
- Child Process: Python code execution
Problem: "Connecting..." status never changes
Solutions:
- β
Ensure signaling server is running (
npm run server) - β Check if port 3000 is available
- β Verify both peers are running the app
- β Check DevTools console for error messages
- β Try creating a new room
Problem: "Room does not exist"
Solutions:
- β Create the room FIRST on one peer
- β Then join from the other peer
- β Use the exact Room ID (case-sensitive)
- β Ensure both peers are connected to the same signaling server
Problem: "Failed to connect to signaling server"
Solutions:
- β
Start the signaling server:
npm run server - β Check if port 3000 is blocked by firewall
- β
Verify the server URL in
renderer.js(default:http://localhost:3000)
Problem: Python code doesn't execute
Solutions:
- β
Ensure Python is installed and accessible via
pythoncommand - β Check Python path in system environment variables
- β
Try running
python --versionin terminal to verify installation
Problem: JavaScript code errors
Solutions:
- β Check DevTools console for detailed error messages
- β
Ensure Node.js modules are available (if using
require()) - β Verify code syntax is correct
Problem: Can't connect between different computers
Solutions:
- β Ensure both computers are on the same network
- β Check firewall settings (allow port 3000)
- β
For internet connection, configure STUN/TURN servers in
p2p-manager.js - β Verify signaling server is accessible from both computers
- Code execution happens with the same permissions as the user running the app
- No sandboxing is implemented (code can access file system, network, etc.)
- Use only with trusted peers on secure networks
- Consider implementing authentication and code validation for production use
npm start- Start the Electron applicationnpm run server- Start the signaling server
Feel free to submit issues, fork the repository, and create pull requests for any improvements.
ISC
Happy coding! If you encounter any issues, check the troubleshooting section or open an issue on GitHub.