agentfense 0.2.1__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.
agentfense/__init__.py ADDED
@@ -0,0 +1,191 @@
1
+ """AgentFense - Python client for the AgentFense service.
2
+
3
+ This SDK provides both low-level and high-level APIs for interacting
4
+ with the Sandbox service, with support for both synchronous and asynchronous
5
+ operations.
6
+
7
+ High-Level API (Recommended):
8
+ Use the Sandbox class for the simplest experience:
9
+
10
+ >>> from agentfense import Sandbox
11
+ >>>
12
+ >>> # One-liner to create and run commands in a sandbox
13
+ >>> with Sandbox.from_local("./my-project") as sandbox:
14
+ ... result = sandbox.run("python main.py")
15
+ ... print(result.stdout)
16
+ >>>
17
+ >>> # With Docker and resource limits
18
+ >>> with Sandbox.from_local(
19
+ ... "./my-project",
20
+ ... preset="agent-safe",
21
+ ... runtime=RuntimeType.DOCKER,
22
+ ... image="python:3.11-slim",
23
+ ... resources=ResourceLimits(memory_bytes=512*1024*1024),
24
+ ... ) as sandbox:
25
+ ... result = sandbox.run("pytest")
26
+
27
+ Async API:
28
+ Use AsyncSandbox for async/await operations:
29
+
30
+ >>> from agentfense import AsyncSandbox
31
+ >>>
32
+ >>> async with await AsyncSandbox.from_local("./my-project") as sandbox:
33
+ ... result = await sandbox.run("python main.py")
34
+ ... print(result.stdout)
35
+
36
+ Low-Level API:
37
+ Use SandboxClient for fine-grained control:
38
+
39
+ >>> from agentfense import SandboxClient
40
+ >>>
41
+ >>> client = SandboxClient(endpoint="localhost:9000")
42
+ >>>
43
+ >>> # Create a codebase
44
+ >>> codebase = client.create_codebase(name="my-project", owner_id="user_123")
45
+ >>>
46
+ >>> # Upload a file
47
+ >>> client.upload_file(codebase.id, "hello.py", b'print("Hello, World!")')
48
+ >>>
49
+ >>> # Create a sandbox with permissions
50
+ >>> sandbox = client.create_sandbox(
51
+ ... codebase_id=codebase.id,
52
+ ... permissions=[
53
+ ... {"pattern": "**/*.py", "permission": "read"},
54
+ ... {"pattern": "/docs/**", "permission": "write"},
55
+ ... ]
56
+ ... )
57
+ >>>
58
+ >>> # Start the sandbox
59
+ >>> client.start_sandbox(sandbox.id)
60
+ >>>
61
+ >>> # Execute a command
62
+ >>> result = client.exec(sandbox.id, command="python hello.py")
63
+ >>> print(result.stdout) # Output: Hello, World!
64
+ >>>
65
+ >>> # Clean up
66
+ >>> client.destroy_sandbox(sandbox.id)
67
+ >>> client.delete_codebase(codebase.id)
68
+ """
69
+
70
+ from .client import SandboxClient, SessionWrapper
71
+ from .sandbox import Sandbox
72
+ from ._async import AsyncSandbox, AsyncSandboxClient, AsyncSessionWrapper
73
+ from .types import (
74
+ Codebase,
75
+ ExecResult,
76
+ FileInfo,
77
+ Permission,
78
+ PatternType,
79
+ PermissionRule,
80
+ ResourceLimits,
81
+ RuntimeType,
82
+ Sandbox as SandboxInfo,
83
+ SandboxStatus,
84
+ Session,
85
+ SessionStatus,
86
+ UploadResult,
87
+ )
88
+ from .presets import (
89
+ PRESETS,
90
+ PRESET_AGENT_SAFE,
91
+ PRESET_READ_ONLY,
92
+ PRESET_FULL_ACCESS,
93
+ PRESET_DEVELOPMENT,
94
+ PRESET_VIEW_ONLY,
95
+ get_preset,
96
+ get_preset_dicts,
97
+ extend_preset,
98
+ list_presets,
99
+ register_preset,
100
+ )
101
+ from .exceptions import (
102
+ SandboxError,
103
+ SandboxNotFoundError,
104
+ SandboxNotRunningError,
105
+ CodebaseError,
106
+ CodebaseNotFoundError,
107
+ FileNotFoundError,
108
+ CommandTimeoutError,
109
+ CommandExecutionError,
110
+ PermissionDeniedError,
111
+ SessionError,
112
+ SessionNotFoundError,
113
+ SessionClosedError,
114
+ ResourceLimitExceededError,
115
+ InvalidConfigurationError,
116
+ UploadError,
117
+ ConnectionError,
118
+ )
119
+ from .utils import (
120
+ walk_directory,
121
+ parse_ignore_file,
122
+ human_readable_size,
123
+ generate_codebase_name,
124
+ generate_owner_id,
125
+ count_files,
126
+ )
127
+
128
+ __version__ = "0.2.0"
129
+ __all__ = [
130
+ # High-level API (sync)
131
+ "Sandbox",
132
+ # High-level API (async)
133
+ "AsyncSandbox",
134
+ # Low-level client (sync)
135
+ "SandboxClient",
136
+ "SessionWrapper",
137
+ # Low-level client (async)
138
+ "AsyncSandboxClient",
139
+ "AsyncSessionWrapper",
140
+ # Types
141
+ "Codebase",
142
+ "ExecResult",
143
+ "FileInfo",
144
+ "Permission",
145
+ "PatternType",
146
+ "PermissionRule",
147
+ "ResourceLimits",
148
+ "RuntimeType",
149
+ "SandboxInfo",
150
+ "SandboxStatus",
151
+ "Session",
152
+ "SessionStatus",
153
+ "UploadResult",
154
+ # Presets
155
+ "PRESETS",
156
+ "PRESET_AGENT_SAFE",
157
+ "PRESET_READ_ONLY",
158
+ "PRESET_FULL_ACCESS",
159
+ "PRESET_DEVELOPMENT",
160
+ "PRESET_VIEW_ONLY",
161
+ "get_preset",
162
+ "get_preset_dicts",
163
+ "extend_preset",
164
+ "list_presets",
165
+ "register_preset",
166
+ # Exceptions
167
+ "SandboxError",
168
+ "SandboxNotFoundError",
169
+ "SandboxNotRunningError",
170
+ "CodebaseError",
171
+ "CodebaseNotFoundError",
172
+ "FileNotFoundError",
173
+ "CommandTimeoutError",
174
+ "CommandExecutionError",
175
+ "PermissionDeniedError",
176
+ "SessionError",
177
+ "SessionNotFoundError",
178
+ "SessionClosedError",
179
+ "ResourceLimitExceededError",
180
+ "InvalidConfigurationError",
181
+ "UploadError",
182
+ "ConnectionError",
183
+ # Utilities
184
+ "walk_directory",
185
+ "parse_ignore_file",
186
+ "human_readable_size",
187
+ "generate_codebase_name",
188
+ "generate_owner_id",
189
+ "count_files",
190
+ ]
191
+
@@ -0,0 +1,21 @@
1
+ """Async API for AgentFense SDK.
2
+
3
+ This module provides asynchronous versions of the Sandbox SDK classes,
4
+ allowing for non-blocking operations in async/await codebases.
5
+
6
+ Example:
7
+ >>> from agentfense import AsyncSandbox
8
+ >>>
9
+ >>> async with AsyncSandbox.from_local("./project") as sandbox:
10
+ ... result = await sandbox.run("python main.py")
11
+ ... print(result.stdout)
12
+ """
13
+
14
+ from .client import AsyncSandboxClient, AsyncSessionWrapper
15
+ from .sandbox import AsyncSandbox
16
+
17
+ __all__ = [
18
+ "AsyncSandboxClient",
19
+ "AsyncSessionWrapper",
20
+ "AsyncSandbox",
21
+ ]