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
```python
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](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Matt Brockman <matt.brockman@e2b.dev>
1.4 KiB
@e2b/python-sdk
| @e2b/python-sdk |
|---|
| patch |
feat(python-sdk): add a logger option for request/debug logging
You can now pass a standard library logging.Logger to Sandbox.create /
AsyncSandbox.create (and the static Sandbox.connect(sandbox_id, ...)) to
route that sandbox's request/response logs to your own logger. The logger is
stored on the sandbox and propagates to all of its later operations —
including control-plane calls such as kill, pause, set_timeout, and
get_info. Matching the JavaScript SDK, logger is a construction-time option
and is not a per-request parameter that those methods accept from the
caller. The stdlib logging.Logger is used directly as the adapter instead of
a custom interface.
The logger is wired into the API client, the envd client, and the RPC
(ConnectRPC) path. Mirroring the JS SDK: requests log at INFO, successful API
and unary RPC responses at INFO, streamed RPC messages at DEBUG, and failed
API responses (status >= 400) at ERROR. When no logger is supplied, the SDK
emits no request/response logging at all (also matching the JS SDK).
Volume content operations continue to accept logger per call via
VolumeApiParams, matching the JS Volume API.
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") # request/response logged via `logger`