-
Notifications
You must be signed in to change notification settings - Fork 40
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
Discussion questions and comparison #22
Comments
Comparison of Isolation in Code Interpreter and Codebox APIFirst question:The codebox api provides isolation because it runs via API but my code-interpreter runs locally so there is no isolation in there because it runs locally and don't need any, only if you convert this project to API then you would need isolation environment. Second question:Setting Up Code-Interpreter as an API in DockerTo set up
Create a # Use an official Python runtime as a parent image
FROM python:3.9-slim
# Set the working directory in the container
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Make port 8080 available to the world outside this container
EXPOSE 8080
# Define environment variable
ENV NAME CodeInterpreterAPI
# Run app.py when the container launches
CMD ["python", "app.py"]
Specify the required Python packages:
Create a Flask application to handle code execution requests: from flask import Flask, request, jsonify
from codeinterpreter import CodeInterpreterSession
app = Flask(__name__)
@app.route('/execute', methods=['POST'])
def execute_code():
data = request.get_json()
code = data.get("code", "")
with CodeInterpreterSession() as session:
response = session.generate_response(code)
return jsonify({"output": response.content})
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080)
Build the Docker image and run the container: docker build -t codeinterpreter-api .
docker run -p 8080:8080 codeinterpreter-api
You can test the API using curl -X POST http://localhost:8080/execute -H "Content-Type: application/json" -d '{"code": "print(\'Hello, World!\')"}' This setup provides a basic HTTP API for running Python code using the Code-Interpreter within a Docker container. The code execution can be isolated and sandboxed using Docker to ensure security. |
Thanks for the response! Follow up question, how would you handle an issue like trying to generate a docx file where the default lib docx is not valid for py3, and it should use python-docx instead. I had multiple attempts but it always errored trying to install the wrong lib. How would you overwrite it's attempts to install the wrong lib? |
If you have specific issues then please create issues for that i will try to solve it. Regarding isolation its only for API, but running in Docker or Jupyter kernel can be features please request them. |
Apologies for the issue but I didn't see a better discussion space/tab in GH or other location to put these.
The text was updated successfully, but these errors were encountered: