ExecutionContainer
ExecutionContainer
ExecutionContainer(
tag: str = DEFAULT_TAG,
binds: dict[str, str] | None = None,
env: dict[str, str] | None = None,
executor_port: int | None = None,
resource_port: int | None = None,
port_allocation_timeout: float = 10,
show_pull_progress: bool = True,
)
Context manager for the lifecycle of a code execution Docker container. A code execution container provides:
- a Jupyter Kernel Gateway for stateful code execution
in IPython kernels. Clients connect to it via
ExecutionClient
on the container's executor host port. - a resource server for downloading Python module sources and registering MCP servers.
Clients connect to it via
ResourceClient
on the container's resource host port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tag
|
str
|
Name and optionally tag of the |
DEFAULT_TAG
|
binds
|
dict[str, str] | None
|
A dictionary mapping host paths to container paths for bind mounts.
Host paths may be relative or absolute. Container paths must be relative
and are created as subdirectories of |
None
|
env
|
dict[str, str] | None
|
Environment variables to set in the container |
None
|
executor_port
|
int | None
|
Host port for the container's executor port. A random port is allocated if not specified. |
None
|
resource_port
|
int | None
|
Host port for the container's resource port. A random port is allocated if not specified. |
None
|
port_allocation_timeout
|
float
|
Maximum time in seconds to wait for port random allocation. |
10
|
show_pull_progress
|
bool
|
Whether to show progress when pulling the Docker image. |
True
|
Source code in ipybox/container.py
executor_port
property
executor_port: int
The host port of the container's executor port. Either an application-defined
executor_port
via the constructor or a dynamically allocated random port.
Raises:
Type | Description |
---|---|
RuntimeError
|
If the container is not running and an application-defined port was not provided. |
resource_port
property
resource_port: int
The host port of the container's resource port. Either an application-defined
resource_port
via the constructor or a dynamically allocated random port.
Raises:
Type | Description |
---|---|
RuntimeError
|
If the container is not running and an application-defined port was not provided. |
kill
async
Kills and removes the current code execution Docker container.