Skip to content

feat(python-sdk): add logger option for request/debug logging#1409

Open
mishushakov wants to merge 3 commits into
mainfrom
mishushakov/python-logger-connection-option
Open

feat(python-sdk): add logger option for request/debug logging#1409
mishushakov wants to merge 3 commits into
mainfrom
mishushakov/python-logger-connection-option

Conversation

@mishushakov

@mishushakov mishushakov commented Jun 9, 2026

Copy link
Copy Markdown
Member

Adds a logger option (a standard library logging.Logger) to Sandbox.create/AsyncSandbox.create and the static Sandbox.connect(sandbox_id, ...), wired into the API client, the envd client, the volume content client, and the RPC (ConnectRPC) path. The logger is stored on the sandbox and propagates to all of its later operations — including control-plane calls like kill/pause/set_timeout/get_info (via get_api_params) — so logging keeps working after construction; mirroring the JS SDK, logger is a construction-time option and not a public per-request parameter those methods accept from the caller, and nothing is logged unless a logger is supplied. The stdlib logging.Logger is used directly as the adapter (no ported JS Logger interface), and log levels match JS: requests at INFO, successful API and unary RPC responses at INFO, streamed RPC messages at DEBUG, failed API responses (status >= 400) at ERROR. The always-on module-level (e2b.*) request logging at the transport layer was removed in favor of this opt-in client-layer logging, and volume content operations continue to accept logger per call via VolumeApiParams to match the JS Volume API. Includes a changeset and unit tests in tests/test_logging_option.py.

Usage

import logging
from e2b import Sandbox

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("my-app.e2b")

sbx = Sandbox.create(logger=logger)
sbx.commands.run("echo hello")   # RPC logged via `logger`
sbx.set_timeout(60)              # control-plane call also logged via `logger`

🤖 Generated with Claude Code

Add a `logger` option (standard library `logging.Logger`) to
`Sandbox.create`/`connect` and `AsyncSandbox.create`/`connect`, wired into the
API client, envd client, volume content client, and the RPC (ConnectRPC) path.
Mirrors the JS SDK: `logger` is a construction-time option (not a per-request
ApiParams field), and logging is emitted only when a logger is supplied.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3b0d16c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@e2b/python-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cursor

cursor Bot commented Jun 9, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Wide SDK surface change plus removal of implicit logging may break operator visibility; opt-in logs may include request URLs.

Overview
Opt-in logger on Sandbox.create / static connect replaces always-on e2b.* HTTP transport logging, so upgrades lose default request/response logs unless a logger is passed (intentional for JS parity but behavior-breaking for existing setups).

make_logging_event_hooks logs response status only on the httpx path while ConnectRPC logs include the URL; envd/API lines are less informative than the removed transport logs.

Static control-plane helpers (Sandbox.kill, get_info, etc.) take ApiParams only, so there is no typed way to attach a logger on those calls without an existing sandbox ConnectionConfig from get_api_params().

Reviewed by Cursor Bugbot for commit 3b0d16c. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from 32c6252. Download artifacts from this workflow run.

JS SDK (e2b@2.28.2-mishushakov-python-logger-connection-option.0):

npm install ./e2b-2.28.2-mishushakov-python-logger-connection-option.0.tgz

CLI (@e2b/cli@2.11.1-mishushakov-python-logger-connection-option.0):

npm install ./e2b-cli-2.11.1-mishushakov-python-logger-connection-option.0.tgz

Python SDK (e2b==2.27.0+mishushakov-python-logger-connection-option):

pip install ./e2b-2.27.0+mishushakov.python.logger.connection.option-py3-none-any.whl

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 25416ed. Configure here.

Comment thread packages/python-sdk/e2b/sandbox_sync/main.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25416ed3cc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/python-sdk/e2b/connection_config.py
mishushakov and others added 2 commits June 9, 2026 15:14
`get_api_params` now carries the sandbox's stored logger so the throwaway
ConnectionConfig that instance control-plane methods (kill, pause, set_timeout,
get_info, connect) rebuild keeps logging with the construction-time logger.
Also drop the misleading `logger` arg from instance `connect()` — the returned
instance is unchanged, so it could never adopt a new logger; `logger` remains
on `create` and the static `connect(sandbox_id, ...)` construction paths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace the off-schema dict mutation with an internal `ApiParamsWithLogger`
TypedDict (ApiParams + logger), so the construction-time logger is propagated
through a typed structure rather than an untyped key assignment.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant