code-sandboxes 0.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,141 @@
1
+ # Copyright (c) 2025-2026 Datalayer, Inc.
2
+ #
3
+ # BSD 3-Clause License
4
+
5
+ """Code Sandboxes - Safe, isolated environments for AI code execution.
6
+
7
+ This package provides different sandbox implementations for executing
8
+ code safely, inspired by E2B and Modal:
9
+
10
+ - LocalEvalSandbox: Simple Python exec() based, for development/testing
11
+ - LocalDockerSandbox: Docker container based, good isolation (future)
12
+ - DatalayerSandbox: Cloud-based Datalayer runtime, full isolation
13
+
14
+ Features:
15
+ - Code execution with streaming support
16
+ - Filesystem operations (read, write, list, upload, download)
17
+ - Command execution (run, exec, spawn)
18
+ - Context management for state persistence
19
+ - Snapshot support (for datalayer-runtime)
20
+ - GPU and resource configuration
21
+
22
+ Example:
23
+ from code_sandboxes import Sandbox
24
+
25
+ # Create a sandbox (defaults to datalayer-runtime)
26
+ with Sandbox.create(variant="local-eval") as sandbox:
27
+ # Execute code
28
+ result = sandbox.run_code("x = 1 + 1")
29
+ result = sandbox.run_code("print(x)") # prints 2
30
+
31
+ # Filesystem operations
32
+ sandbox.files.write("/data/test.txt", "Hello World")
33
+ content = sandbox.files.read("/data/test.txt")
34
+
35
+ # Command execution
36
+ result = sandbox.commands.run("ls -la")
37
+
38
+ E2B-style usage:
39
+ sandbox = Sandbox.create(timeout=60) # 60 second timeout
40
+ result = sandbox.run_code('print("hello")')
41
+ files = sandbox.files.list("/")
42
+
43
+ Modal-style usage:
44
+ sandbox = Sandbox.create(gpu="T4", environment="python-gpu-env")
45
+ process = sandbox.commands.exec("python", "-c", "print('hello')")
46
+ for line in process.stdout:
47
+ print(line)
48
+ """
49
+
50
+ from .base import Sandbox, SandboxVariant
51
+ from .commands import CommandResult, ProcessHandle, SandboxCommands
52
+ from .exceptions import (
53
+ ContextNotFoundError,
54
+ SandboxAuthenticationError,
55
+ SandboxConfigurationError,
56
+ SandboxConnectionError,
57
+ SandboxError,
58
+ SandboxExecutionError,
59
+ SandboxNotStartedError,
60
+ SandboxQuotaExceededError,
61
+ SandboxResourceError,
62
+ SandboxSnapshotError,
63
+ SandboxTimeoutError,
64
+ VariableNotFoundError,
65
+ )
66
+ from .filesystem import (
67
+ FileInfo,
68
+ FileType,
69
+ FileWatchEvent,
70
+ FileWatchEventType,
71
+ SandboxFileHandle,
72
+ SandboxFilesystem,
73
+ )
74
+ from .local.eval_sandbox import LocalEvalSandbox
75
+ from .models import (
76
+ Context,
77
+ Execution,
78
+ ExecutionError,
79
+ GPUType,
80
+ Logs,
81
+ MIMEType,
82
+ OutputHandler,
83
+ OutputMessage,
84
+ ResourceConfig,
85
+ Result,
86
+ SandboxConfig,
87
+ SandboxInfo,
88
+ SandboxStatus,
89
+ SnapshotInfo,
90
+ TunnelInfo,
91
+ )
92
+ from .remote.datalayer_sandbox import DatalayerSandbox
93
+
94
+ __all__ = [
95
+ # Main sandbox class
96
+ "Sandbox",
97
+ "SandboxVariant",
98
+ # Sandbox implementations
99
+ "LocalEvalSandbox",
100
+ "DatalayerSandbox",
101
+ # Filesystem
102
+ "SandboxFilesystem",
103
+ "SandboxFileHandle",
104
+ "FileInfo",
105
+ "FileType",
106
+ "FileWatchEvent",
107
+ "FileWatchEventType",
108
+ # Commands
109
+ "SandboxCommands",
110
+ "CommandResult",
111
+ "ProcessHandle",
112
+ # Models
113
+ "Context",
114
+ "Execution",
115
+ "ExecutionError",
116
+ "Logs",
117
+ "MIMEType",
118
+ "OutputHandler",
119
+ "OutputMessage",
120
+ "Result",
121
+ "SandboxConfig",
122
+ "SandboxInfo",
123
+ "SandboxStatus",
124
+ "ResourceConfig",
125
+ "GPUType",
126
+ "SnapshotInfo",
127
+ "TunnelInfo",
128
+ # Exceptions
129
+ "SandboxError",
130
+ "SandboxTimeoutError",
131
+ "SandboxExecutionError",
132
+ "SandboxNotStartedError",
133
+ "SandboxConnectionError",
134
+ "SandboxConfigurationError",
135
+ "SandboxSnapshotError",
136
+ "SandboxResourceError",
137
+ "SandboxAuthenticationError",
138
+ "SandboxQuotaExceededError",
139
+ "ContextNotFoundError",
140
+ "VariableNotFoundError",
141
+ ]
@@ -0,0 +1,6 @@
1
+ #
2
+ # BSD 3-Clause License
3
+
4
+ """Code Sandboxes."""
5
+
6
+ __version__ = "0.0.2"