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

Link to my 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/", line 534, in _run_script
    exec(code, module.__dict__)
  File "/mount/src/physaid/", line 64, in <module>
  File "/usr/local/lib/python3.9/asyncio/", line 647, in run_until_complete
    return future.result()
  File "/mount/src/physaid/", line 58, in initiate_chat
    await User.a_initiate_chat(
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/agentchat/", 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/", 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/", line 523, in a_receive
    reply = await self.a_generate_reply(sender=sender)
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/agentchat/", line 1012, in a_generate_reply
    final, reply = await reply_func(
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/agentchat/", 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/", 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/", 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/", line 1118, in execute_code_blocks
    exitcode, logs, image = self.run_code(
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/agentchat/", line 1095, in run_code
    return execute_code(code, **kwargs)
  File "/home/adminuser/venv/lib/python3.9/site-packages/autogen/", 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/'

Python = 3.11, Streamlit=1.28.0,Docker=6.1.3


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


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,

Hi @Antimony00000001

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