PermissionError: [Errno 13] Permission denied when executing code block

Link to my app: https://physaid-2dzlxyjtyaxj9og2jolc5r.streamlit.app

The error occurs when an agent tries to execute a code block. (It can be triggered by chosing research workflow and ask for some code)
I can’t share my github repo now becuase I’ve got api keys inside.

The error message:

>>>>>>>> EXECUTING CODE BLOCK 0 (inferred language is python)...
2023-12-17 23:56:12.279 Uncaught app exception
Traceback (most recent call last):
  File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
    exec(code, module.__dict__)
  File "/mount/src/physaid/main.py", line 64, in <module>
    loop.run_until_complete(initiate_chat())
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/mount/src/physaid/main.py", line 58, in initiate_chat
    await User.a_initiate_chat(
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/agentchat/conversable_agent.py", line 579, in a_initiate_chat
    await self.a_send(self.generate_init_message(**context), recipient, silent=silent)
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/agentchat/conversable_agent.py", line 403, in a_send
    await recipient.a_receive(message, self, request_reply, silent)
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/agentchat/conversable_agent.py", line 523, in a_receive
    reply = await self.a_generate_reply(sender=sender)
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/agentchat/conversable_agent.py", line 1012, in a_generate_reply
    final, reply = await reply_func(
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/agentchat/groupchat.py", line 391, in a_run_chat
    reply = await speaker.a_generate_reply(sender=self)
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/agentchat/conversable_agent.py", line 1016, in a_generate_reply
    final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"])
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/agentchat/conversable_agent.py", line 691, in generate_code_execution_reply
    exitcode, logs = self.execute_code_blocks(code_blocks)
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/agentchat/conversable_agent.py", line 1118, in execute_code_blocks
    exitcode, logs, image = self.run_code(
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/agentchat/conversable_agent.py", line 1095, in run_code
    return execute_code(code, **kwargs)
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/code_utils.py", line 302, in execute_code
    with open(filepath, "w", encoding="utf-8") as fout:
PermissionError: [Errno 13] Permission denied: '/home/adminuser/venv/lib/python3.9/site-packages/autogen/extensions/tmp_code_3b5c4cb8dd707ebc13ec2e529b5910b1.py'

Python = 3.11, Streamlit=1.28.0,Docker=6.1.3

Hi

It seems you’re encountering a file permission error, please see this StackOverflow post for ideas on resolving this:

Hi,

Thanks for your response. I still can’t get it solved. I wonder if streamlit cloud supports llm agents executing codes and storing files? If so can you give me a reference to an example that would really help.

Much Appreciated,
Albus

Hi @Antimony00000001

It can be used in a Streamlit app, here’s a simple example using create_pandas_dataframe_agent via langchain: