Fix E2B package install failure
Quick answer
To fix
e2b package install failures, ensure you install the correct package e2b-code-interpreter via pip install e2b-code-interpreter. Avoid installing a non-existent package named e2b, which causes errors.PREREQUISITES
Python 3.8+pip 22+Internet connection for pip install
Setup
Install the correct e2b-code-interpreter package using pip. The common mistake is trying to install e2b, which does not exist on PyPI.
Set your E2B_API_KEY environment variable before running code that uses the sandbox.
pip install e2b-code-interpreter output
Collecting e2b-code-interpreter Downloading e2b_code_interpreter-1.0.0-py3-none-any.whl (15 kB) Installing collected packages: e2b-code-interpreter Successfully installed e2b-code-interpreter-1.0.0
Step by step
Use the Sandbox class from e2b_code_interpreter with your API key from environment variables. Run code inside the sandbox and print the output.
import os
from e2b_code_interpreter import Sandbox
sandbox = Sandbox(api_key=os.environ["E2B_API_KEY"])
execution = sandbox.run_code("print('Hello from sandbox')")
print(execution.text)
sandbox.close() output
Hello from sandbox
Common variations
You can upload files to the sandbox using sandbox.files.write(filename, data) and install packages inside the sandbox by running pip commands via run_code. The package is synchronous; async usage is not supported.
sandbox.files.write("data.csv", open("local.csv", "rb").read())
sandbox.run_code("import subprocess; subprocess.run(['pip','install','pandas'])") Troubleshooting
- If
pip install e2bfails, switch topip install e2b-code-interpreter. - Ensure your Python version is 3.8 or higher.
- Set the
E2B_API_KEYenvironment variable correctly before running code. - If you get import errors, verify the package is installed in the correct Python environment.
Key Takeaways
- Always install the package with
pip install e2b-code-interpreter, note2b. - Set
E2B_API_KEYenvironment variable before using the sandbox. - Use
Sandbox.run_code()to execute code safely inside the sandbox. - Check Python version and environment if installation or import fails.