Skip to content

Conversation

mishushakov
Copy link
Member

@mishushakov mishushakov commented Aug 20, 2025

Changes

  • Setting env vars now appends a generated code snippet to the user code with no extra request to Jupyter.
  • Resetting env vars happens in a separate request in background after response so that the return of the last cell stays unmodified.
  • Because resetting happens in background but the new execution will wait until the previous cleanup task has been completed (to ensure correctness), fast subsequent requests might get delayed due that reason

Remarks

  • I suppose, we can cut even more ms when starting new kernels by making change_current_directory append to the user code on first request like the env vars.

Benchmark

Tested locally in debug mode.

Sample code used:

from e2b_code_interpreter import Sandbox
import time

sbx = Sandbox(debug=True)

# Start time measure
start_time = time.time()
sbx.run_code("os.environ['hello']", envs={"hello": "world"})
end_time = time.time()
print(f"Python kernel time taken: {(end_time - start_time) * 1000:.2f} milliseconds")

Before

Python kernel time taken: 116.38 milliseconds

After

Python kernel time taken: 18.64 milliseconds

@mishushakov mishushakov self-assigned this Aug 20, 2025
@mishushakov mishushakov added the improvement Improvement for current functionality label Aug 20, 2025
Copy link

linear bot commented Aug 20, 2025

cursor[bot]

This comment was marked as outdated.

@mishushakov
Copy link
Member Author

@cursor review

cursor[bot]

This comment was marked as outdated.

@mishushakov
Copy link
Member Author

@cursor review

cursor[bot]

This comment was marked as outdated.

@mishushakov
Copy link
Member Author

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no bugs!

Comment @cursor review or bugbot run to trigger another review on this PR

@jakubno jakubno merged commit f56a182 into main Aug 21, 2025
7 checks passed
@jakubno jakubno deleted the performance-regression-when-setting-env-vars-on-first-e2b-2850 branch August 21, 2025 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement for current functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants