You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Especially in case of heavy sandbox customization we don't want to spawn a new VM every time we need to execute code, especially in circumstances when time of inactivity is negligible.
Changes 🏗️
Added two now blocks inside autogpt_platform/backend/backend/blocks/code_executor.py which split the logic of the CodeExecutionBlock in two parts: InstantiationBlock and StepExecutionBlock.
The overall setup shall be the done in the InstantiationBlock which then passes as output the sandbox_id which identifies the sandbox instance.
At a later stage any line of code can be executed through StepExecutionBlock inside the same instance using the e2b library function sandbox = Sandbox.connect(sandbox_id=sandbox_id, api_key=api_key). Variables and memory form earlier executions or instantiation are persisted.
Beware, this approach does not make use of the beta apis to pause and resume an instance. By using the approach above the VM will likely be killed after the timeout inactivity set at instantiation time.
New Features:
InstantiationBlock Class:
Added a new class to instantiate an isolated sandbox environment with internet access for code execution. This class includes input and output schemas, methods for running and executing code, and handles sandbox setup commands and code execution.
StepExecutionBlock Class:
Introduced a new class to execute code in a previously instantiated sandbox environment. This class also includes input and output schemas, methods for running and executing step code, and handles connecting to an existing sandbox for code execution.
Minor Changes:
ProgrammingLanguage Enum:
Added a blank line for better readability within the ProgrammingLanguage enum definition.
Here are some key observations to aid the review process:
⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 Security concerns
Code Execution: The blocks allow arbitrary code execution in sandboxed environments. While sandboxed, there's no validation or restriction on the code being executed, which could potentially be used for malicious purposes if the sandbox environment is not properly isolated. Consider adding code validation or execution restrictions.
The InstantiationBlock's execute_code method creates a sandbox but doesn't handle cleanup if an error occurs during setup_commands execution. This could lead to orphaned sandbox instances.
The StepExecutionBlock doesn't verify if the sandbox is still active before executing code. Since sandbox instances can timeout, this could lead to runtime errors.
sandbox=Sandbox.connect(sandbox_id=sandbox_id, api_key=api_key)
ifnotsandbox:
raiseException("Sandbox not found")
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Especially in case of heavy sandbox customization we don't want to spawn a new VM every time we need to execute code, especially in circumstances when time of inactivity is negligible.
Changes 🏗️
Added two now blocks inside
autogpt_platform/backend/backend/blocks/code_executor.py
which split the logic of the CodeExecutionBlock in two parts: InstantiationBlock and StepExecutionBlock.The overall setup shall be the done in the InstantiationBlock which then passes as output the
sandbox_id
which identifies the sandbox instance.At a later stage any line of code can be executed through StepExecutionBlock inside the same instance using the e2b library function
sandbox = Sandbox.connect(sandbox_id=sandbox_id, api_key=api_key)
. Variables and memory form earlier executions or instantiation are persisted.Beware, this approach does not make use of the beta apis to pause and resume an instance. By using the approach above the VM will likely be killed after the timeout inactivity set at instantiation time.
New Features:
InstantiationBlock Class:
StepExecutionBlock Class:
Minor Changes:
ProgrammingLanguage
enum definition.