A Flask-based web terminal backend that provides terminal functionality via WebSockets. This server allows clients (like iOS apps) to connect to and interact with terminal sessions running on the server.
- Create and manage multiple terminal sessions
- Real-time terminal interaction via WebSockets
- Terminal state persistence
- Full terminal emulation using PTY (Pseudo Terminal) and terminal emulator
- Session resize capability to match client display
- RESTful API for terminal session management
- File management API for working with files
- In-terminal editing with multiple editors (vim, nano, emacs, joe)
- Python development capabilities with pip package management
- Automatic cleanup of inactive sessions
The system is designed with the following components:
- Terminal Session Model - Represents a terminal session with a PTY process and terminal emulator
- Terminal Service - Manages terminal sessions and handles input/output routing
- Web API - REST endpoints for terminal session and file management
- WebSocket API - Real-time communication for terminal input/output
- Flask - Web framework
- Flask-SocketIO - WebSocket support
- Eventlet - Async WSGI server
- PTYProcess - Pseudo-terminal management
- Pyte - Terminal emulator
- Terminal Editors - vim, nano, emacs, joe for in-terminal file editing
# Clone the repository
git clone https://github.com/yourusername/termux-web-terminal.git
cd termux-web-terminal
# Run the development server
./run_local.shAfter starting the server, you can run the test script to verify everything is working:
./test_api.pydocker build -t termux-web-terminal .
docker run -p 5000:5000 termux-web-terminalThis project includes a render.yaml file for easy deployment to Render.com. See DEPLOY_TO_RENDER.md for detailed instructions.
- GET
/api/terminal/sessions- List all terminal sessions - POST
/api/terminal/sessions- Create a new terminal session - GET
/api/terminal/sessions/{session_id}- Get session details - POST
/api/terminal/sessions/{session_id}/size- Resize a session - DELETE
/api/terminal/sessions/{session_id}- Terminate a session - GET
/api/files- List files in a directory - POST
/api/files- Create a file or directory - PUT
/api/files- Update a file's content - DELETE
/api/files- Delete a file or directory - GET
/api/files/read- Read file content - GET
/api/files/download- Download a file - POST
/api/files/upload- Upload a file - POST
/api/files/rename- Rename a file or directory - GET
/api/python/packages- List installed packages - POST
/api/python/packages- Install a package - DELETE
/api/python/packages- Uninstall a package - GET
/api/python/packages/search- Search for packages - GET
/api/python/packages/info- Get package info - GET
/api/python/venvs- List virtual environments - POST
/api/python/venvs- Create a virtual environment - DELETE
/api/python/venvs- Delete a virtual environment - POST
/api/python/run- Run Python code
See client-example.html for a complete example of using the WebSocket API.
The ios_client_integration.swift file provides a Swift client implementation for iOS apps to connect to this backend.
For details on using the terminal interface, see TERMINAL_USAGE.md.
This project is open-source and available under the MIT License.