-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(sandbox): adding docker sandbox #1517
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fdcfb87
feat(sandbox): adding docker sandbox
ArslanSaleem bd18ebf
Merge branch 'release/v3' into feat/sandbox
ArslanSaleem 3c72f5a
feat(sandbox): add serializer and deserializer
ArslanSaleem f0b5c87
Merge branch 'release/v3' into feat/sandbox
ArslanSaleem b630742
feat(dockerSandbox): complete implementation of docker sandbox
ArslanSaleem f880b01
fix(sandbox): spell mistakes
ArslanSaleem 221c1dc
fix(sandbox): fix readme command
ArslanSaleem a341e07
fix(langchan): poetry lock file update
ArslanSaleem 52d0489
Update pandasai/sandbox/sandbox.py
ArslanSaleem 3ed84fe
fix(docker): make docker not use network
ArslanSaleem d0dc4c0
Merge branch 'feat/sandbox' of https://github.com/gventuri/pandas-ai …
ArslanSaleem afb593f
Merge branch 'release/v3' into feat/sandbox
ArslanSaleem a78039d
fix(ruff): errors in code formatting
ArslanSaleem 5d99577
feat(sandbox): add notebook for docker sandbox
ArslanSaleem 1806976
added notebook and documentation for sandbox
gdcsinaptik 878f325
feat(Sandbox): typo and update documentation
ArslanSaleem 7c18a8c
fix(docker): create docker from command line
ArslanSaleem bf1bf4f
Update extensions/sandbox/docker/pandasai_docker/docker_sandbox.py
ArslanSaleem 79f71f6
Update extensions/sandbox/docker/pandasai_docker/docker_sandbox.py
ArslanSaleem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Execute code in a sandbox\n", | ||
"\n", | ||
"To enhance security and protect yourself from malicious code through prompt injection, \n", | ||
"we make it possible to run code in a sandbox environment.\n", | ||
"This notebook explains how to do it." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Install the package\n", | ||
"\n", | ||
"First of all you need to install the python package. You can use pip to install it" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%pip install pandasai-docker" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Execute the code in the sandbox with the agent\n", | ||
"\n", | ||
"Please keep in mind the sandbox works offline. \n", | ||
"Once you have installed the package, you can start the sandbox with the following code.\n", | ||
"For the purpose of this example, we are going to use bambooLLM as the LLM chosen for the agent." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandasai as pai\n", | ||
"from pandasai import Agent\n", | ||
"from pandasai_docker import DockerSandbox\n", | ||
"\n", | ||
"pai.set_api_key(\"YOUR_API_KEY\")\n", | ||
"\n", | ||
"# initialize the sandbox\n", | ||
"sandbox = DockerSandbox()\n", | ||
"sandbox.start()\n", | ||
"\n", | ||
"# read a csv as df\n", | ||
"df = pai.read_csv(\"./data/heart.csv\")\n", | ||
"\n", | ||
"# pass the csv and the sandbox to the agent\n", | ||
"agent = Agent([df], memory_size=10, sandbox=sandbox)\n", | ||
"\n", | ||
"# Chat with the Agent\n", | ||
"response = agent.chat(\"plot top five artists streams\")\n", | ||
"\n", | ||
"# stop the sandbox (docker container)\n", | ||
"sandbox.stop()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Customize the sandbox\n", | ||
"\n", | ||
"You can decide the name and path of your sandbox by passing them as positional arguments in the DockerSandbox()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"sandbox = DockerSandbox(\"pandaai-sandbox\", \"/path/to/Dockerfile\")\n", | ||
"\n", | ||
"# read a csv as df\n", | ||
"df = pai.read_csv(\"./data/heart.csv\")\n", | ||
"\n", | ||
"# pass the csv and the sandbox to the agent\n", | ||
"agent = Agent([df], memory_size=10, sandbox=sandbox)\n", | ||
"\n", | ||
"# Chat with the Agent\n", | ||
"response = agent.chat(\"plot top five artists streams\")\n", | ||
"\n", | ||
"sandbox.stop()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Docker Sandbox Extension for PandasAI | ||
|
||
## Installation | ||
|
||
You can install this extension using poetry: | ||
|
||
```bash | ||
poetry add pandasai-docker | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM python:3.9 | ||
|
||
LABEL image_name="pandasai-sandbox" | ||
|
||
# Install required Python packages | ||
RUN pip install pandas numpy matplotlib | ||
|
||
# Set the working directory inside the container | ||
WORKDIR /app | ||
|
||
# Default command keeps the container running (useful for testing or debugging) | ||
CMD ["sleep", "infinity"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .docker_sandbox import DockerSandbox | ||
|
||
__all__ = ["DockerSandbox"] |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it would be useful to specify that the docker daemon must be running in the machine before using this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scaliseraoul Yes definitely we should mention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArslanSaleem great, can we add it accordingly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done