Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ class ChatRequest(BaseModel):
|
|
| 15 |
|
| 16 |
def execute_in_sandbox(command: str):
|
| 17 |
try:
|
| 18 |
-
#
|
| 19 |
full_command = f"cd /tmp && {command}"
|
| 20 |
|
| 21 |
result = subprocess.run(
|
|
@@ -23,7 +23,7 @@ def execute_in_sandbox(command: str):
|
|
| 23 |
shell=True,
|
| 24 |
capture_output=True,
|
| 25 |
text=True,
|
| 26 |
-
timeout=600
|
| 27 |
)
|
| 28 |
return {
|
| 29 |
"stdout": result.stdout,
|
|
@@ -37,12 +37,13 @@ def execute_in_sandbox(command: str):
|
|
| 37 |
async def agent_chat(request: ChatRequest):
|
| 38 |
user_prompt = request.message
|
| 39 |
|
| 40 |
-
# AI ko
|
| 41 |
system_instruction = (
|
| 42 |
"You are an AI Agent Builder operating inside a limited Linux sandbox. "
|
| 43 |
-
"You
|
| 44 |
-
"
|
| 45 |
-
"
|
|
|
|
| 46 |
)
|
| 47 |
|
| 48 |
try:
|
|
@@ -55,10 +56,11 @@ async def agent_chat(request: ChatRequest):
|
|
| 55 |
ai_response = response.text
|
| 56 |
|
| 57 |
if "```bash" in ai_response:
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
| 62 |
|
| 63 |
return {"agent_response": ai_response}
|
| 64 |
|
|
|
|
| 15 |
|
| 16 |
def execute_in_sandbox(command: str):
|
| 17 |
try:
|
| 18 |
+
# /tmp directory me user ko bina sudo ke full write access milti hai
|
| 19 |
full_command = f"cd /tmp && {command}"
|
| 20 |
|
| 21 |
result = subprocess.run(
|
|
|
|
| 23 |
shell=True,
|
| 24 |
capture_output=True,
|
| 25 |
text=True,
|
| 26 |
+
timeout=600
|
| 27 |
)
|
| 28 |
return {
|
| 29 |
"stdout": result.stdout,
|
|
|
|
| 37 |
async def agent_chat(request: ChatRequest):
|
| 38 |
user_prompt = request.message
|
| 39 |
|
| 40 |
+
# AI ko strictly bol rahe hain ki sudo use na kare, balki /tmp me local tools setup kare
|
| 41 |
system_instruction = (
|
| 42 |
"You are an AI Agent Builder operating inside a limited Linux sandbox. "
|
| 43 |
+
"You CANNOT use 'sudo' or root commands because the platform restricts it. "
|
| 44 |
+
"Instead, you must install everything locally inside the `/tmp` directory using pre-compiled binaries, curl, or local zip extractions. "
|
| 45 |
+
"For example, to use Flutter, download its tar.xz via curl into /tmp, extract it, and run it from there directly. "
|
| 46 |
+
"If you want to execute any bash setup, return the exact script inside a triple backtick block starting with 'bash'."
|
| 47 |
)
|
| 48 |
|
| 49 |
try:
|
|
|
|
| 56 |
ai_response = response.text
|
| 57 |
|
| 58 |
if "```bash" in ai_response:
|
| 59 |
+
parts = ai_response.split("```bash")
|
| 60 |
+
if len(parts) > 1:
|
| 61 |
+
command = parts[1].split("```")[0].strip()
|
| 62 |
+
exec_result = execute_in_sandbox(command)
|
| 63 |
+
return {"agent_response": ai_response, "execution_result": exec_result}
|
| 64 |
|
| 65 |
return {"agent_response": ai_response}
|
| 66 |
|