Skip to content

Fix python.lang.security.audit.exec-detected.exec-detected #1679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions pandasai/core/code_execution/code_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,16 @@ def add_to_env(self, key: str, value: Any) -> None:
"""
self._environment[key] = value

def execute(self, code: str) -> dict:
try:
exec(code, self._environment)
except Exception as e:
raise CodeExecutionError("Code execution failed") from e
return self._environment

def execute_and_return_result(self, code: str) -> Any:
def execute(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing import for Optional, Dict, and definition for CodeExecutionResult. Ensure these types are imported or defined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add or update unit tests to cover the new execute() method, especially testing the behavior with the context parameter and result extraction.

self, code: str, context: Optional[Dict[str, Any]] = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added context parameter is not used in the implementation. Ensure it is integrated or remove it.

) -> CodeExecutionResult:
"""
Executes the return updated environment
"""
self.execute(code)

# Get the result
if "result" not in self._environment:
raise NoResultFoundError("No result returned")
Execute the code and return the result.

return self._environment.get("result", None)
Args:
code (str): The code to execute.
context (Dict[str, Any], optional): The context to execute the code in.

@property
def environment(self) -> dict:
return self._environment
Returns:
CodeExecutionResult: The result of the code execution.
"""