Python code execution sandbox based on IPython and Docker
Project description
ipybox
ipybox is a lightweight, stateful and secure Python code execution sandbox built with IPython and Docker. Designed for AI agents that interact with their environment through code execution, like freeact agents, it is also well-suited for general-purpose code execution. ipybox is fully open-source and free to use, distributed under the Apache 2.0 license.
Features
- Secure Execution: Executes code in Docker container locally or remotely
- Stateful Execution: Maintains state across code executions using IPython kernels
- Output Streaming: Provides immediate feedback through direct output streaming
- Plotting Support: Enables downloading of plots created with visualization libraries
- MCP Support: Generate Python functions from MCP tools and use them during code execution
- Dependency Management: Supports package installation during runtime or at build time
- Resource Management: Context manager based container and IPython kernel lifecycle management
- Reproducible Environments: Ensures consistent execution environments across different systems
Find out more in the user guide.
Quickstart
Install ipybox Python package:
pip install ipybox
Execute Python code inside ipybox:
import asyncio
from ipybox import ExecutionClient, ExecutionContainer
async def main():
async with ExecutionContainer(tag="ghcr.io/gradion-ai/ipybox:minimal") as container:
async with ExecutionClient(port=container.executor_port) as client:
result = await client.execute("print('Hello, world!')")
print(f"Output: {result.text}")
if __name__ == "__main__":
asyncio.run(main())
MCP Support
ipybox also supports the generation of Python functions from MCP tools. When called, they execute the corresponding tools on the MCP server.
import asyncio
from ipybox import ExecutionClient, ExecutionContainer, ResourceClient
async def main():
server_params = {
"command": "uvx",
"args": ["mcp-server-fetch"],
}
async with ExecutionContainer(tag="ghcr.io/gradion-ai/ipybox:minimal") as container:
async with ResourceClient(port=container.resource_port) as client:
# generate Python functions from MCP server metadata
generate_result = await client.generate_mcp_sources(
relpath="mcpgen",
server_name="fetchurl",
server_params=server_params,
)
# tool names provided by MCP server
assert generate_result == ["fetch"]
# retrieve generated sources if needed
generated_sources = await client.get_mcp_sources(
relpath="mcpgen",
server_name="fetchurl",
)
assert "def fetch(params: Params) -> str:" in generated_sources["fetch"]
async with ExecutionClient(port=container.executor_port) as client:
# call the generated function in the container
result = await client.execute("""
from mcpgen.fetchurl.fetch import Params, fetch
print(fetch(Params(url="https://www.gradion.ai")))
""")
print(result.text[:375])
if __name__ == "__main__":
asyncio.run(main())
The script executes the generated fetch function in the ipybox container and then prints the first 375 characters of the fetched content:
Contents of https://www.gradion.ai/:
```
___ _
____ __________ _____/ (_)___ ____ ____ _(_)
/ __ `/ ___/ __ `/ __ / / __ \/ __ \ / __ `/ /
/ /_/ / / / /_/ / /_/ / / /_/ / / / // /_/ / /
\__, /_/ \__,_/\__,_/_/\____/_/ /_(_)__,_/_/
/____/
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ipybox-0.4.4.tar.gz.
File metadata
- Download URL: ipybox-0.4.4.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52f5aa8db2b0856e83d0fd15107fc0ae1d1adb3dc7b717af2f3d73aed8d2baa9
|
|
| MD5 |
44dc2ebc2477a9f22053b94ad4a9f83e
|
|
| BLAKE2b-256 |
1268a0637439a4b85e7003e2868f4833d92f3c0aa9b8395d421a1d4d9f52bc77
|
Provenance
The following attestation bundles were made for ipybox-0.4.4.tar.gz:
Publisher:
release.yml on gradion-ai/ipybox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ipybox-0.4.4.tar.gz -
Subject digest:
52f5aa8db2b0856e83d0fd15107fc0ae1d1adb3dc7b717af2f3d73aed8d2baa9 - Sigstore transparency entry: 219742536
- Sigstore integration time:
-
Permalink:
gradion-ai/ipybox@616c57d16c5aeef917541fb25466e005814fcfc6 -
Branch / Tag:
refs/tags/0.4.4 - Owner: https://github.com/gradion-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@616c57d16c5aeef917541fb25466e005814fcfc6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ipybox-0.4.4-py3-none-any.whl.
File metadata
- Download URL: ipybox-0.4.4-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed1ca3d10688720918239865b1cf16672ae9d0430ec8d5dc837c4404b958c7d1
|
|
| MD5 |
77a5909f1b9557a09e5271bad269d9fe
|
|
| BLAKE2b-256 |
9c18a6dc0ed74c5d169f54af3e70cb65be68ff51735377f16461d382a50b63ee
|
Provenance
The following attestation bundles were made for ipybox-0.4.4-py3-none-any.whl:
Publisher:
release.yml on gradion-ai/ipybox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ipybox-0.4.4-py3-none-any.whl -
Subject digest:
ed1ca3d10688720918239865b1cf16672ae9d0430ec8d5dc837c4404b958c7d1 - Sigstore transparency entry: 219742538
- Sigstore integration time:
-
Permalink:
gradion-ai/ipybox@616c57d16c5aeef917541fb25466e005814fcfc6 -
Branch / Tag:
refs/tags/0.4.4 - Owner: https://github.com/gradion-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@616c57d16c5aeef917541fb25466e005814fcfc6 -
Trigger Event:
push
-
Statement type: