Skip to content

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

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

feat(python-sdk): add logger option for request/debug logging#1409
mishushakov wants to merge 16 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: f75d99d

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 touch across HTTP/RPC clients with a default logging behavior change (silent unless opt-in), which can break operators who depended on implicit SDK logs without changing application code.

Overview
Adds optional stdlib logging.Logger on sandbox create/connect (and volume per-call), wired through API httpx event hooks, envd HTTP clients, ConnectRPC, and get_api_params so control-plane calls keep the same logger.

Without logger=, the SDK no longer emits the request/response lines that used to come from module loggers on HTTP transports and ApiClient hooks, so existing setups that relied on default e2b.* logging will go quiet unless they pass a logger (behavior change vs prior releases).

TransportWithLogger / AsyncTransportWithLogger (and volume equivalents) still exist but no longer perform logging; only httpx event_hooks log when a logger is supplied, so the transport class names are misleading.

CI runs Windows pytest without --numprocesses=4. Unit coverage is in tests/test_logging_option.py; changeset documents the feature.

Reviewed by Cursor Bugbot for commit f75d99d. 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 856c219. Download artifacts from this workflow run.

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

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

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

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

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

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

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 4 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>
…gger-connection-option

# Conflicts:
#	packages/python-sdk/e2b/api/client_async/__init__.py
#	packages/python-sdk/e2b/api/client_sync/__init__.py
#	packages/python-sdk/e2b/connection_config.py
#	packages/python-sdk/e2b/sandbox_sync/commands/command.py
#	packages/python-sdk/e2b/sandbox_sync/commands/pty.py
#	packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
#	packages/python-sdk/e2b/sandbox_sync/main.py
Comment thread packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
mishushakov and others added 3 commits June 11, 2026 22:00
Filesystem rebuilds a per-thread envd httpx.Client via `_create_envd_api`;
attach the logging event hooks there too so file upload/download requests on
worker threads honor the sandbox's `logger` instead of going unlogged after
transport-level logging was removed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…gger-connection-option

# Conflicts:
#	packages/python-sdk/e2b/api/__init__.py
#	packages/python-sdk/e2b/sandbox_sync/main.py
…gger-connection-option

# Conflicts:
#	packages/python-sdk/e2b/api/client_async/__init__.py
#	packages/python-sdk/e2b/volume/client_async/__init__.py
#	packages/python-sdk/e2b/volume/client_sync/__init__.py
…gger-connection-option

# Conflicts:
#	packages/python-sdk/e2b/sandbox_async/main.py
#	packages/python-sdk/e2b/sandbox_sync/main.py

@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 96c1322. Configure here.

Comment thread packages/python-sdk/e2b/sandbox_sync/commands/command.py
mishushakov and others added 5 commits June 15, 2026 23:32
…ents

Sync Commands and Pty build their own thread-local httpx.Client instances
for envd HTTP traffic (health checks, etc.), but unlike the sync filesystem
client they were missing make_logging_event_hooks. As a result envd requests
on those clients were not logged even when the sandbox was created with a
logger. Mirror the filesystem client so all sync envd traffic respects the
configured logger.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…gger-connection-option

# Conflicts:
#	packages/python-sdk/e2b/connection_config.py
@mishushakov

Copy link
Copy Markdown
Member Author

@matthewlouisbrockman was the two commits added on purpose? if it's not related to the PR, i'd move that

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.

3 participants