This PR removes the built in node-pty terminal and adds integration with E2B's sandbox API. This fixes security issues with deployment and allows any number of sandboxes to run simultaneously.
It also fixes several bugs:
Fixes a bug where new socket connections are made every time React refreshes the virtual DOM.
Fixes a bug limiting the total number of user sandboxes to eight.
Adds error handling to socket event listeners, so file or execution errors don't crash the whole server.
Implementation
Notes/limitations:
The preview panel now dynamically updates it's URL to the correct sandbox, but the port number is still hardcoded.
Sandboxes are closed immediately when the last browser tab using the sandbox is closed.
As before, files updated in the editor update in the terminal, but not the other way around.
Terminology: Because of the word "sandbox" is already commonplace in the code, I decided to call E2B sandboxes containers in the source. However it would make a lot of sense to call those sandboxes and call sandbox projects projects.
Testing
To test this PR:
Add E2B_API_KEY to /backend/server/.env (available for free at E2B).
Run the frontend and backend, and open any sandbox.
Commands run in the terminal will indicate a fresh Debian Linux system.
Run npm install && npm run dev in the terminal and refresh the preview panel to see the live preview.
Edit a source code file and save changes to test hot reloading.
Description
This PR removes the built in node-pty terminal and adds integration with E2B's sandbox API. This fixes security issues with deployment and allows any number of sandboxes to run simultaneously.
It also fixes several bugs:
Implementation
Notes/limitations:
Terminology: Because of the word "sandbox" is already commonplace in the code, I decided to call E2B sandboxes containers in the source. However it would make a lot of sense to call those sandboxes and call sandbox projects projects.
Testing
To test this PR:
/backend/server/.env
(available for free at E2B).npm install && npm run dev
in the terminal and refresh the preview panel to see the live preview.