AutoGPT icon indicating copy to clipboard operation
AutoGPT copied to clipboard

add mode for python execution

Open Igniscode opened this issue 2 years ago • 10 comments

divide docker mode and venv mode for python execution

Background

To run execute_python_file, which is currently built into autogpt, user needs to install docker and create docker-image separately, which you feel is unnecessary and unreasonable. (I watched multiple issues because of this, for example #92 #1896 ) It is likely to be a difficult task for beginners or those who are not familiar with Docker use.

Changes

Therefore, in python execution, the venv mode and the Docker mode were separated and implemented so that the user could choose how to execute the code in the .env file.

Documentation

Relevant information is annotated in code as comments

Test Plan

Same environment, I tested docker mode(legacy) and venv mode and they work same.

PR Quality Checklist

  • [v ] My pull request is atomic and focuses on a single change.
  • [v ] I have thoroughly tested my changes with multiple different prompts.
  • [v ] I have considered potential risks and mitigations for my changes.
  • [v ] I have documented my changes clearly and comprehensively.
  • [v ] I have not snuck in any "extra" small tweaks changes

Igniscode avatar May 02 '23 22:05 Igniscode

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview May 18, 2023 4:57am

vercel[bot] avatar May 02 '23 22:05 vercel[bot]

This is a mass message from the AutoGPT core team. Our apologies for the ongoing delay in processing PRs. This is because we are re-architecting the AutoGPT core!

For more details (and for infor on joining our Discord), please refer to: https://github.com/Significant-Gravitas/Auto-GPT/wiki/Architecting

p-i- avatar May 05 '23 00:05 p-i-

if this is committed "as is", it would make sense for auto-gpt to run inside a separate environment - i.e. using chroot or ideally using a dedicated "autogpt" user. That way, there's another layer of security added when it comes to $HOME

The same restriction should then apply for execute_shell commands obviously. if $USER is not "autogpt", the script should internally disable code execution completely.

Boostrix avatar May 07 '23 10:05 Boostrix

if this is committed "as is", it would make sense for auto-gpt to run inside a separate environment - i.e. using chroot or ideally using a dedicated "autogpt" user. That way, there's another layer of security added when it comes to $HOME

The same restriction should then apply for execute_shell commands obviously. if $USER is not "autogpt", the script should internally disable code execution completely.

Thank you for the excellent feedback on my request. While using venv provides some minimum security, adding a new account seems like a much safer idea.

Igniscode avatar May 08 '23 18:05 Igniscode

I did copy that advice into the source tree and opened a corresponding PR:

  • #3961

Boostrix avatar May 08 '23 18:05 Boostrix

I did copy that advice into the source tree and opened a corresponding PR:

Cool! I will also consider implementing rules for executing code based on user permissions.

Igniscode avatar May 08 '23 18:05 Igniscode

there are already some hard-coded heuristics to detect if agpt is running inside docker - I suppose the "separate user" idea could be implemented via a corresponding env file setting, and that would simply require autogpt to run as the user "autogpt", and if it doesn't, disable executive functions - if anybody disagrees, they can edit the env file and opt out obviously

Boostrix avatar May 08 '23 18:05 Boostrix

there are already some hard-coded heuristics to detect if agpt is running inside docker - I suppose the "separate user" idea could be implemented via a corresponding env file setting, and that would simply require autogpt to run as the user "autogpt", and if it doesn't, disable executive functions - if anybody disagrees, they can edit the env file and opt out obviously

I understand your point, I think the "separate user" idea should be implemented in a separate pull request because it may have implications for other commands. Thanks for inform it!

Igniscode avatar May 08 '23 19:05 Igniscode

sure, they won't accept multiple features in a single PR anyway

Also see:

  • https://github.com/Significant-Gravitas/Auto-GPT/issues/4045

Boostrix avatar May 08 '23 19:05 Boostrix

Codecov Report

Patch coverage: 43.63% and project coverage change: -0.41 :warning:

Comparison is base (dc41db9) 62.67% compared to head (8e424e8) 62.27%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3713      +/-   ##
==========================================
- Coverage   62.67%   62.27%   -0.41%     
==========================================
  Files          74       74              
  Lines        3400     3430      +30     
  Branches      495      501       +6     
==========================================
+ Hits         2131     2136       +5     
- Misses       1120     1143      +23     
- Partials      149      151       +2     
Impacted Files Coverage Δ
autogpt/main.py 0.00% <0.00%> (ø)
autogpt/commands/execute_code.py 53.19% <42.00%> (-16.38%) :arrow_down:
autogpt/config/config.py 75.00% <75.00%> (ø)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar May 15 '23 08:05 codecov[bot]

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar May 22 '23 20:05 github-actions[bot]

Does venv provide the same degree of sandboxing as docker?

Pwuts avatar Jun 07 '23 00:06 Pwuts

No.

Boostrix avatar Jun 07 '23 05:06 Boostrix

Since venv does not provide the same degree of sandboxing as docker, they are only interchangeable if the user knows what they are doing and have purposefully disabled the workspace restriction.

Pwuts avatar Jun 07 '23 09:06 Pwuts

Instead of merging this, I'd like to assure you that we are working on an improvement to the CLI that should make it a lot easier to run Auto-GPT (with docker).

  • #4604 You would be welcome to contribute, just ping us on Discord and we'll see who can do what. :)

Pwuts avatar Jun 07 '23 09:06 Pwuts