THED2 commited on
Commit
2656772
·
verified ·
1 Parent(s): 948d53e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -15,7 +15,7 @@ class ChatRequest(BaseModel):
15
 
16
  def execute_in_sandbox(command: str):
17
  try:
18
- # Commands hamesha writeable directory (/tmp) me run ho, isliye cd /tmp lagaya hai
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 # 10 mins timeout taaki installation aaram se ho sake
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 instruction do ki use jo chahiye wo khud bash command se install kare (e.g., flutter, sdk)
41
  system_instruction = (
42
  "You are an AI Agent Builder operating inside a limited Linux sandbox. "
43
- "You have full permission to download and install necessary tools (like Flutter, Node.js, Android cmdline-tools) "
44
- "using bash commands when required. Always perform your operations inside the `/tmp` directory because it has write permissions. "
45
- "If you want to execute any tool or bash setup, return the exact script inside a triple backtick block starting with 'bash'."
 
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
- command = ai_response.split("
59
- ```bash")[1].split("```")[0].strip()
60
- exec_result = execute_in_sandbox(command)
61
- return {"agent_response": ai_response, "execution_result": exec_result}
 
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