agent-sandbox-backends 0.1.0__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.
- agent_sandbox_backends/__init__.py +97 -0
- agent_sandbox_backends/_internal/__init__.py +1 -0
- agent_sandbox_backends/_internal/bounded_output.py +50 -0
- agent_sandbox_backends/_internal/ids.py +38 -0
- agent_sandbox_backends/api.py +528 -0
- agent_sandbox_backends/application/__init__.py +1 -0
- agent_sandbox_backends/application/allocator.py +135 -0
- agent_sandbox_backends/application/backend.py +677 -0
- agent_sandbox_backends/application/command_handle.py +64 -0
- agent_sandbox_backends/application/operation_pipeline.py +280 -0
- agent_sandbox_backends/application/output_writer.py +169 -0
- agent_sandbox_backends/concurrency/__init__.py +12 -0
- agent_sandbox_backends/concurrency/activity.py +51 -0
- agent_sandbox_backends/concurrency/keyed_rw_lock.py +135 -0
- agent_sandbox_backends/concurrency/lease.py +114 -0
- agent_sandbox_backends/concurrency/limiter.py +41 -0
- agent_sandbox_backends/config/__init__.py +23 -0
- agent_sandbox_backends/config/command.py +20 -0
- agent_sandbox_backends/config/concurrency.py +36 -0
- agent_sandbox_backends/config/models.py +12 -0
- agent_sandbox_backends/config/retry.py +19 -0
- agent_sandbox_backends/config/upload.py +37 -0
- agent_sandbox_backends/domain/__init__.py +1 -0
- agent_sandbox_backends/domain/base.py +5 -0
- agent_sandbox_backends/domain/capabilities.py +58 -0
- agent_sandbox_backends/domain/commands.py +72 -0
- agent_sandbox_backends/domain/context.py +55 -0
- agent_sandbox_backends/domain/errors.py +172 -0
- agent_sandbox_backends/domain/files.py +33 -0
- agent_sandbox_backends/domain/identity.py +14 -0
- agent_sandbox_backends/domain/operations.py +38 -0
- agent_sandbox_backends/domain/sandbox.py +40 -0
- agent_sandbox_backends/domain/uploads.py +71 -0
- agent_sandbox_backends/helper/__init__.py +13 -0
- agent_sandbox_backends/helper/build.py +72 -0
- agent_sandbox_backends/helper/source/__init__.py +1 -0
- agent_sandbox_backends/helper/source/history_helper.py +1465 -0
- agent_sandbox_backends/helper/source/upload_helper.py +311 -0
- agent_sandbox_backends/history/__init__.py +18 -0
- agent_sandbox_backends/history/bootstrap_outbox.py +214 -0
- agent_sandbox_backends/history/config.py +98 -0
- agent_sandbox_backends/history/encoding.py +217 -0
- agent_sandbox_backends/history/memory.py +36 -0
- agent_sandbox_backends/history/none.py +17 -0
- agent_sandbox_backends/history/provider_transport.py +240 -0
- agent_sandbox_backends/history/sandbox.py +319 -0
- agent_sandbox_backends/history/sqlalchemy.py +623 -0
- agent_sandbox_backends/history/sqlite.py +255 -0
- agent_sandbox_backends/integrations/__init__.py +1 -0
- agent_sandbox_backends/integrations/deepagents/__init__.py +17 -0
- agent_sandbox_backends/integrations/deepagents/adapter.py +413 -0
- agent_sandbox_backends/integrations/deepagents/compatibility.py +88 -0
- agent_sandbox_backends/integrations/deepagents/runtime.py +66 -0
- agent_sandbox_backends/ports/__init__.py +1 -0
- agent_sandbox_backends/ports/history_store.py +18 -0
- agent_sandbox_backends/ports/history_transport.py +26 -0
- agent_sandbox_backends/ports/lease_store.py +21 -0
- agent_sandbox_backends/ports/provider.py +64 -0
- agent_sandbox_backends/providers/__init__.py +3 -0
- agent_sandbox_backends/providers/mock/__init__.py +3 -0
- agent_sandbox_backends/providers/mock/provider.py +412 -0
- agent_sandbox_backends/providers/opensandbox/__init__.py +3 -0
- agent_sandbox_backends/providers/opensandbox/provider.py +664 -0
- agent_sandbox_backends/providers/registry.py +52 -0
- agent_sandbox_backends/py.typed +0 -0
- agent_sandbox_backends/security/__init__.py +14 -0
- agent_sandbox_backends/security/archive.py +110 -0
- agent_sandbox_backends/security/upload_scanner.py +228 -0
- agent_sandbox_backends/upload/__init__.py +10 -0
- agent_sandbox_backends/upload/archive.py +77 -0
- agent_sandbox_backends/upload/provider_transport.py +204 -0
- agent_sandbox_backends/upload/service.py +243 -0
- agent_sandbox_backends/version.py +2 -0
- agent_sandbox_backends-0.1.0.dist-info/METADATA +294 -0
- agent_sandbox_backends-0.1.0.dist-info/RECORD +77 -0
- agent_sandbox_backends-0.1.0.dist-info/WHEEL +4 -0
- agent_sandbox_backends-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
from agent_sandbox_backends.api import (
|
|
2
|
+
SandboxBackend,
|
|
3
|
+
create_allocator,
|
|
4
|
+
create_backend,
|
|
5
|
+
create_opensandbox_backend,
|
|
6
|
+
)
|
|
7
|
+
from agent_sandbox_backends.application.allocator import SandboxAllocator
|
|
8
|
+
from agent_sandbox_backends.application.command_handle import CommandHandle
|
|
9
|
+
from agent_sandbox_backends.config.command import CommandResultConfig
|
|
10
|
+
from agent_sandbox_backends.config.concurrency import ConcurrencyConfig
|
|
11
|
+
from agent_sandbox_backends.config.models import BackendMode, CleanupPolicy
|
|
12
|
+
from agent_sandbox_backends.config.retry import RetryConfig
|
|
13
|
+
from agent_sandbox_backends.config.upload import UploadConfig
|
|
14
|
+
from agent_sandbox_backends.domain.capabilities import Capabilities, CapabilitySupport
|
|
15
|
+
from agent_sandbox_backends.domain.commands import (
|
|
16
|
+
CommandOutputChunk,
|
|
17
|
+
CommandStream,
|
|
18
|
+
ExecRequest,
|
|
19
|
+
ExecResult,
|
|
20
|
+
)
|
|
21
|
+
from agent_sandbox_backends.domain.errors import (
|
|
22
|
+
BackendCloseError,
|
|
23
|
+
CommandExecutionError,
|
|
24
|
+
CommandQueueTimeoutError,
|
|
25
|
+
ConcurrentModificationError,
|
|
26
|
+
FileNotFoundError,
|
|
27
|
+
HistoryDatabaseError,
|
|
28
|
+
HistoryTransportError,
|
|
29
|
+
LockAcquisitionTimeoutError,
|
|
30
|
+
ProviderError,
|
|
31
|
+
SandboxBackendError,
|
|
32
|
+
SandboxDeletingError,
|
|
33
|
+
SandboxNotFoundError,
|
|
34
|
+
SandboxStateError,
|
|
35
|
+
UnsupportedCapabilityError,
|
|
36
|
+
UploadPartialFailureError,
|
|
37
|
+
UploadPolicyError,
|
|
38
|
+
)
|
|
39
|
+
from agent_sandbox_backends.domain.files import FileEntry, FileKind, WriteFileRequest
|
|
40
|
+
from agent_sandbox_backends.domain.identity import SandboxRef
|
|
41
|
+
from agent_sandbox_backends.domain.sandbox import (
|
|
42
|
+
SANDBOX_NAME_METADATA_KEY,
|
|
43
|
+
SandboxInfo,
|
|
44
|
+
SandboxState,
|
|
45
|
+
)
|
|
46
|
+
from agent_sandbox_backends.domain.uploads import UploadResult, UploadSpec
|
|
47
|
+
from agent_sandbox_backends.history.config import HistoryConfig, HistoryMode
|
|
48
|
+
from agent_sandbox_backends.version import __version__
|
|
49
|
+
|
|
50
|
+
__all__ = [
|
|
51
|
+
"SANDBOX_NAME_METADATA_KEY",
|
|
52
|
+
"BackendCloseError",
|
|
53
|
+
"BackendMode",
|
|
54
|
+
"Capabilities",
|
|
55
|
+
"CapabilitySupport",
|
|
56
|
+
"CleanupPolicy",
|
|
57
|
+
"CommandExecutionError",
|
|
58
|
+
"CommandHandle",
|
|
59
|
+
"CommandOutputChunk",
|
|
60
|
+
"CommandQueueTimeoutError",
|
|
61
|
+
"CommandResultConfig",
|
|
62
|
+
"CommandStream",
|
|
63
|
+
"ConcurrencyConfig",
|
|
64
|
+
"ConcurrentModificationError",
|
|
65
|
+
"ExecRequest",
|
|
66
|
+
"ExecResult",
|
|
67
|
+
"FileEntry",
|
|
68
|
+
"FileKind",
|
|
69
|
+
"FileNotFoundError",
|
|
70
|
+
"HistoryConfig",
|
|
71
|
+
"HistoryDatabaseError",
|
|
72
|
+
"HistoryMode",
|
|
73
|
+
"HistoryTransportError",
|
|
74
|
+
"LockAcquisitionTimeoutError",
|
|
75
|
+
"ProviderError",
|
|
76
|
+
"RetryConfig",
|
|
77
|
+
"SandboxAllocator",
|
|
78
|
+
"SandboxBackend",
|
|
79
|
+
"SandboxBackendError",
|
|
80
|
+
"SandboxDeletingError",
|
|
81
|
+
"SandboxInfo",
|
|
82
|
+
"SandboxNotFoundError",
|
|
83
|
+
"SandboxRef",
|
|
84
|
+
"SandboxState",
|
|
85
|
+
"SandboxStateError",
|
|
86
|
+
"UnsupportedCapabilityError",
|
|
87
|
+
"UploadConfig",
|
|
88
|
+
"UploadPartialFailureError",
|
|
89
|
+
"UploadPolicyError",
|
|
90
|
+
"UploadResult",
|
|
91
|
+
"UploadSpec",
|
|
92
|
+
"WriteFileRequest",
|
|
93
|
+
"__version__",
|
|
94
|
+
"create_allocator",
|
|
95
|
+
"create_backend",
|
|
96
|
+
"create_opensandbox_backend",
|
|
97
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Internal implementation helpers."""
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections import deque
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BoundedHeadTailBuffer:
|
|
7
|
+
def __init__(self, *, max_bytes: int, tail_bytes: int) -> None:
|
|
8
|
+
self._max_bytes = max_bytes
|
|
9
|
+
self._tail_capacity = min(max_bytes, tail_bytes)
|
|
10
|
+
self._head_capacity = max_bytes - self._tail_capacity
|
|
11
|
+
self._head = bytearray()
|
|
12
|
+
self._tail: deque[bytes] = deque()
|
|
13
|
+
self._tail_size = 0
|
|
14
|
+
self.total_bytes = 0
|
|
15
|
+
|
|
16
|
+
@property
|
|
17
|
+
def truncated(self) -> bool:
|
|
18
|
+
return self.total_bytes > self._max_bytes
|
|
19
|
+
|
|
20
|
+
def append(self, data: bytes) -> None:
|
|
21
|
+
if not data:
|
|
22
|
+
return
|
|
23
|
+
self.total_bytes += len(data)
|
|
24
|
+
head_missing = self._head_capacity - len(self._head)
|
|
25
|
+
if head_missing > 0:
|
|
26
|
+
self._head.extend(data[:head_missing])
|
|
27
|
+
data = data[head_missing:]
|
|
28
|
+
if self._tail_capacity == 0 or not data:
|
|
29
|
+
return
|
|
30
|
+
self._tail.append(data)
|
|
31
|
+
self._tail_size += len(data)
|
|
32
|
+
self._trim_tail()
|
|
33
|
+
|
|
34
|
+
def value(self) -> bytes:
|
|
35
|
+
if not self._tail:
|
|
36
|
+
return bytes(self._head)
|
|
37
|
+
return bytes(self._head) + b"".join(self._tail)
|
|
38
|
+
|
|
39
|
+
def _trim_tail(self) -> None:
|
|
40
|
+
overflow = self._tail_size - self._tail_capacity
|
|
41
|
+
while overflow > 0 and self._tail:
|
|
42
|
+
first = self._tail[0]
|
|
43
|
+
if len(first) <= overflow:
|
|
44
|
+
self._tail.popleft()
|
|
45
|
+
self._tail_size -= len(first)
|
|
46
|
+
overflow -= len(first)
|
|
47
|
+
continue
|
|
48
|
+
self._tail[0] = first[overflow:]
|
|
49
|
+
self._tail_size -= overflow
|
|
50
|
+
overflow = 0
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import secrets
|
|
4
|
+
import threading
|
|
5
|
+
import time
|
|
6
|
+
import uuid
|
|
7
|
+
|
|
8
|
+
_lock = threading.Lock()
|
|
9
|
+
_last_millisecond = -1
|
|
10
|
+
_sequence = 0
|
|
11
|
+
_SEQUENCE_MASK = (1 << 74) - 1
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def uuid7() -> uuid.UUID:
|
|
15
|
+
"""Return a process-monotonic UUIDv7 compatible identifier."""
|
|
16
|
+
global _last_millisecond, _sequence
|
|
17
|
+
|
|
18
|
+
millisecond = time.time_ns() // 1_000_000
|
|
19
|
+
with _lock:
|
|
20
|
+
if millisecond > _last_millisecond:
|
|
21
|
+
_last_millisecond = millisecond
|
|
22
|
+
_sequence = secrets.randbits(74)
|
|
23
|
+
else:
|
|
24
|
+
millisecond = _last_millisecond
|
|
25
|
+
_sequence = (_sequence + 1) & _SEQUENCE_MASK
|
|
26
|
+
if _sequence == 0:
|
|
27
|
+
_last_millisecond += 1
|
|
28
|
+
millisecond = _last_millisecond
|
|
29
|
+
|
|
30
|
+
random_a = (_sequence >> 62) & 0xFFF
|
|
31
|
+
random_b = _sequence & ((1 << 62) - 1)
|
|
32
|
+
|
|
33
|
+
value = (millisecond & ((1 << 48) - 1)) << 80
|
|
34
|
+
value |= 0x7 << 76
|
|
35
|
+
value |= random_a << 64
|
|
36
|
+
value |= 0b10 << 62
|
|
37
|
+
value |= random_b
|
|
38
|
+
return uuid.UUID(int=value)
|