Spaces:
Runtime error
Runtime error
File size: 954 Bytes
8cd8930 6e543a5 8cd8930 6e543a5 8cd8930 398a327 8cd8930 6e543a5 8cd8930 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
import subprocess
app = FastAPI()
@app.get("/")
def root():
return {"status": "ok", "message": "Terminal API is running"}
@app.post("/terminal")
async def run_terminal(req: Request):
data = await req.json()
cmd = data.get("cmd")
if not cmd:
return JSONResponse(
status_code=400,
content={"error": "cmd field is required"}
)
try:
result = subprocess.run(
cmd,
shell=True,
capture_output=True,
text=True,
timeout=1000000000
)
return {
"command": cmd,
"stdout": result.stdout,
"stderr": result.stderr,
"returncode": result.returncode
}
except Exception as e:
return JSONResponse(
status_code=500,
content={"error": str(e)}
) |