A full-stack app that translates natural-language instructions into safe, sandboxed terminal commands and executes them in a restricted environment.
- Backend: FastAPI
- Frontend: Single-page app served by FastAPI (HTML/CSS/JS)
- Safety: Strict validator and non-shell executor for whitelisted primitives only
- Strict LLM system prompt to return JSON-only command plans
- Server-side validator blocking absolute paths, traversal, and unsafe flags
- Safe executor using Python stdlib (no shell) inside
sandbox_root/
- Polished UI with translate → confirm → run flow
backend/app/main.py
— FastAPI app and endpointsbackend/app/llm.py
— LLM integration with fallback translatorbackend/app/validator.py
— JSON schema/command validationbackend/app/executor.py
— Safe execution of allowed primitivesbackend/app/templates/index.html
— Frontend HTMLbackend/app/static/
— Frontend JS/CSSbackend/sandbox_root/
— Created at runtime for isolated ops
- Create a virtual environment
py -m venv .venv
- Activate it
.\.venv\Scripts\Activate
- Install dependencies
pip install -r backend\requirements.txt
- (Optional) Configure OpenAI
- Copy
.env.example
to.env
and setOPENAI_API_KEY
andOPENAI_MODEL
if desired. - Without an API key, a minimal fallback translator is used.
- Run the server (from
backend/
)
uvicorn app.main:app --reload --host 127.0.0.1 --port 8000
- Open the app
- Visit http://127.0.0.1:8000/
- Executor disallows
..
, absolute paths, and recursive deletes. Directories must be empty to remove. - No shell execution; commands are parsed and executed with Python functions.
- UI requires confirmation for ambiguous or destructive actions.
Create .env
(optional):
OPENAI_API_KEY
— API key for your LLM provider (OpenAI-compatible)OPENAI_BASE_URL
— Base URL for API (defaults tohttps://api.openai.com/v1
)OPENAI_MODEL
— Model name (defaults togpt-4o-mini
)
GET /
— UIGET /api/health
— Health checkPOST /api/translate
— Body:{ instruction }
→ Returns translation JSONPOST /api/execute
— Body:{ commands, start_cwd }
→ Returns outputs and final CWD
ls [path]
,pwd
,cd <dir>
,mkdir <dir>
,touch <file>
,cat <file>
rm <file_or_dir>
(dir must be empty)mv <src> <dst>
,cp <src> <dst>
(no directory copy)ps
,mem
echo "text" > file
- Code style: simple and readable. No shell=True anywhere.
- Expand the validator/executor carefully when adding new primitives.
MIT (add your preferred license).