-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sandbox): adding docker sandbox (#1517)
* feat(sandbox): adding docker sandbox * feat(sandbox): add serializer and deserializer * feat(dockerSandbox): complete implementation of docker sandbox * fix(sandbox): spell mistakes * fix(sandbox): fix readme command * fix(langchan): poetry lock file update * Update pandasai/sandbox/sandbox.py Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * fix(docker): make docker not use network * fix(ruff): errors in code formatting * feat(sandbox): add notebook for docker sandbox * added notebook and documentation for sandbox * feat(Sandbox): typo and update documentation * fix(docker): create docker from command line * Update extensions/sandbox/docker/pandasai_docker/docker_sandbox.py Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * Update extensions/sandbox/docker/pandasai_docker/docker_sandbox.py Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> Co-authored-by: gdcsinaptik <[email protected]>
- Loading branch information
1 parent
56bdd8c
commit d4a1d0e
Showing
17 changed files
with
2,980 additions
and
7 deletions.
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.