Skip to content

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

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

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

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
Removes unconditional default HTTP logging across the SDK, which is a user-visible behavior change; the new path touches many clients but is mostly additive wiring with unit tests.

Overview
Adds an optional stdlib logging.Logger on Sandbox.create / AsyncSandbox.create and static Sandbox.connect(sandbox_id, ...), stored on ConnectionConfig and threaded through API httpx event hooks, envd HTTP clients, ConnectRPC (e2b_connect), and volume HTTP clients. Control-plane calls on an existing sandbox keep that logger via internal get_api_params / ApiParamsWithLogger; logger is not on public ApiParams or instance connect().

Always-on transport-level logging on e2b.api / sync and async client modules was removed, so with no logger argument the SDK emits no request/response logs (aligned with the JS SDK). Volume content calls can still pass logger per request through VolumeApiParams. Adds tests/test_logging_option.py and a changeset.

If you relied on the old default e2b.* INFO logs without passing a logger, you must now pass your own logger at sandbox creation/connect to get the same visibility.

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

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

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

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

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

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

pip install ./e2b-2.28.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

@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 8c0bd2d. Configure here.

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
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