Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add on artifact on run python

Jakub Novakc5ccb01201c0
diff --git a/.changeset/little-ties-jump.md b/.changeset/little-ties-jump.md
new file mode 100644
index 000000000..3368ed32b
--- /dev/null
+++ b/.changeset/little-ties-jump.md
@@ -0,0 +1,5 @@
+---
+'@e2b/python-sdk': patch
+---
+
+Add on artifact to run python
diff --git a/packages/python-sdk/e2b/templates/data_analysis.py b/packages/python-sdk/e2b/templates/data_analysis.py
index a9a59a211..7fc342de8 100644
--- a/packages/python-sdk/e2b/templates/data_analysis.py
+++ b/packages/python-sdk/e2b/templates/data_analysis.py
@@ -54,6 +54,7 @@ class DataAnalysis(Session):
code: str,
on_stdout: Optional[Callable[[str], Any]] = None,
on_stderr: Optional[Callable[[str], Any]] = None,
+ on_artifact: Optional[Callable[[Artifact], Any]] = None,
on_exit: Optional[Callable[[int], Any]] = None,
env_vars: Optional[EnvVars] = None,
cwd: str = "",
@@ -63,12 +64,13 @@ class DataAnalysis(Session):
artifacts = set()
def register_artifacts(event: Any) -> None:
+ on_artifact_func = on_artifact or self.on_artifact
if event.operation == "Create":
artifact = Artifact(name=event.path, _session=self)
artifacts.add(artifact)
- if self.on_artifact:
+ if on_artifact_func:
try:
- self.on_artifact(artifact)
+ on_artifact_func(artifact)
except Exception as e:
logger.error("Failed to process artifact", exc_info=e)