marin-shellbox 0.2.282.dev43906453060__tar.gz → 0.2.284.dev43909614052__tar.gz

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.
Files changed (65) hide show
  1. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/PKG-INFO +11 -10
  2. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/README.md +7 -6
  3. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/pyproject.toml +4 -4
  4. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/daytona/machine.py +39 -19
  5. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/daytona/snapshot.py +8 -8
  6. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/test_daytona_machine.py +43 -4
  7. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/.gitignore +0 -0
  8. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/benchmarks/tasktrove/sample.py +0 -0
  9. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/__init__.py +0 -0
  10. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/__init__.py +0 -0
  11. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/daytona/__init__.py +0 -0
  12. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/daytona/bridge.py +0 -0
  13. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/daytona/connection.py +0 -0
  14. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/daytona/process.py +0 -0
  15. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/daytona/snapshot_cli.py +0 -0
  16. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/docker/__init__.py +0 -0
  17. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/docker/machine.py +0 -0
  18. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/gvisor/__init__.py +0 -0
  19. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/gvisor/machine.py +0 -0
  20. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/iris/__init__.py +0 -0
  21. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/iris/machine.py +0 -0
  22. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/local/__init__.py +0 -0
  23. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/local/cgroup.py +0 -0
  24. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/local/images.py +0 -0
  25. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/local/launch.py +0 -0
  26. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/local/machine.py +0 -0
  27. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/local/nix.py +0 -0
  28. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/local/python_environment.py +0 -0
  29. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/local/transfers.py +0 -0
  30. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/qemu/__init__.py +0 -0
  31. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/qemu/bundle.py +0 -0
  32. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/qemu/guest/disk-init +0 -0
  33. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/qemu/guest/init +0 -0
  34. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/qemu/guest/pty-agent.c +0 -0
  35. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/qemu/image.py +0 -0
  36. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/qemu/machine.py +0 -0
  37. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/shellsim/__init__.py +0 -0
  38. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/backends/shellsim/machine.py +0 -0
  39. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/http_service.py +0 -0
  40. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/http_service_guest.py +0 -0
  41. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/image.py +0 -0
  42. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/machine.py +0 -0
  43. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/process_framing.py +0 -0
  44. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/process_session.py +0 -0
  45. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/task.py +0 -0
  46. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/src/shellbox/transfer.py +0 -0
  47. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/conftest.py +0 -0
  48. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/manual/README.md +0 -0
  49. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/manual/check_machine.py +0 -0
  50. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/manual/check_prepared_image.py +0 -0
  51. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/manual/check_qemu_isolation.py +0 -0
  52. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/manual/check_shell.py +0 -0
  53. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/manual/tasktrove_nl2bash_command.sh +0 -0
  54. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/test_daytona_process.py +0 -0
  55. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/test_docker_machine.py +0 -0
  56. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/test_gvisor_machine.py +0 -0
  57. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/test_http_service.py +0 -0
  58. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/test_image_cache.py +0 -0
  59. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/test_iris_machine.py +0 -0
  60. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/test_local_cgroup.py +0 -0
  61. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/test_local_launch.py +0 -0
  62. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/test_local_machine.py +0 -0
  63. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/test_process_session.py +0 -0
  64. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/test_qemu_machine.py +0 -0
  65. {marin_shellbox-0.2.282.dev43906453060 → marin_shellbox-0.2.284.dev43909614052}/tests/test_shellsim_machine.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: marin-shellbox
3
- Version: 0.2.282.dev43906453060
3
+ Version: 0.2.284.dev43909614052
4
4
  Summary: Shell execution machines with local and remote backends
5
5
  Requires-Python: >=3.12
6
6
  Requires-Dist: bubblewrap-bin==0.11.0; sys_platform == 'linux'
@@ -8,14 +8,14 @@ Requires-Dist: httpx>=0.27
8
8
  Requires-Dist: pydantic<3,>=2.12
9
9
  Provides-Extra: daytona
10
10
  Requires-Dist: daytona==0.200.2; extra == 'daytona'
11
- Requires-Dist: marin-rigging==0.2.282.dev43906453060; extra == 'daytona'
11
+ Requires-Dist: marin-rigging==0.2.284.dev43909614052; extra == 'daytona'
12
12
  Provides-Extra: gvisor
13
13
  Provides-Extra: iris
14
- Requires-Dist: marin-iris==0.2.282.dev43906453060; extra == 'iris'
14
+ Requires-Dist: marin-iris==0.2.284.dev43909614052; extra == 'iris'
15
15
  Provides-Extra: qemu
16
16
  Requires-Dist: quicksand-qemu<0.6,>=0.5.12; extra == 'qemu'
17
17
  Provides-Extra: shellsim
18
- Requires-Dist: marin-rigging==0.2.282.dev43906453060; extra == 'shellsim'
18
+ Requires-Dist: marin-rigging==0.2.284.dev43909614052; extra == 'shellsim'
19
19
  Requires-Dist: shellsim[pypi]>=0.1.38; extra == 'shellsim'
20
20
  Description-Content-Type: text/markdown
21
21
 
@@ -43,7 +43,7 @@ The base wheel contains the machine API and guest source. The [vendored Harbor p
43
43
 
44
44
  `factory.check_environment(requirements, spec)` checks task semantics, capabilities and software support before acquisition. Factories retain the requested `MachineSpec`; prepared images and bundles are backend inputs. The check does not promise available capacity or installed executables.
45
45
 
46
- The package provides a Harbor-independent machine interface. QEMU and Docker factories accept a registry reference or a local Dockerfile. QEMU also accepts a `PreparedImage` or a prebuilt guest bundle; Docker accepts a local image. `ShellSimMachineFactory` and `LocalMachineFactory` accept `PackageSpec(pypi_packages=..., tools=...)`; the local factory also accepts `HostImage()`, `PreparedImage` and registry references. Daytona accepts registry images and Dockerfiles at the build context root. Iris accepts registry image references. Local gVisor accepts the same images as Docker. Each `create` returns a fresh machine with a persistent writable filesystem. `run` returns bytes, exit status, and output truncation flags. `upload`, `download`, and `close` complete the common interface.
46
+ The package provides a Harbor-independent machine interface. QEMU and Docker factories accept a registry reference or a local Dockerfile. QEMU also accepts a `PreparedImage` or a prebuilt guest bundle; Docker accepts a local image. `ShellSimMachineFactory` and `LocalMachineFactory` accept `PackageSpec(pypi_packages=..., tools=...)`; the local factory also accepts `HostImage()`, `PreparedImage` and registry references. Daytona accepts registry images and Dockerfiles at the build context root. By default it builds each distinct image once into a reusable account snapshot; `DaytonaImageBuild.DECLARATIVE` builds the image for every sandbox instead and creates no snapshot. Iris accepts registry image references. Local gVisor accepts the same images as Docker. Each `create` returns a fresh machine with a persistent writable filesystem. `run` returns bytes, exit status, and output truncation flags. `upload`, `download`, and `close` complete the common interface.
47
47
 
48
48
  Shared contracts and OCI image preparation live at the package root. Backend machines live under `shellbox.backends.{qemu,shellsim,docker,gvisor,daytona,iris,local}`. Harbor owns the local, Daytona, QEMU and ShellSim environment adapters. Machines retain their runtime between commands; QEMU and ShellSim also support persistent Bash sessions.
49
49
 
@@ -289,15 +289,16 @@ Model commands that run as root can stop other root-owned processes.
289
289
 
290
290
  For Daytona, set `DAYTONA_API_KEY` and `DAYTONA_API_URL`. `DAYTONA_TARGET` is optional.
291
291
  Alternatively, supply a function that creates a configured `AsyncDaytona` client to `DaytonaMachineFactory`.
292
- Each machine owns and closes its client. The factory creates sandboxes from shared
293
- snapshots. Snapshot names derive from the registry reference or build-context contents
294
- and the requested resources. Use immutable image references. A mutable tag can
295
- select a snapshot built from an earlier image. Snapshot creation requires available organization quota.
292
+ Each machine owns and closes its client. In the default build mode, the factory
293
+ creates sandboxes from shared snapshots. Snapshot names derive from the registry
294
+ reference or build-context contents and the requested resources. Use immutable
295
+ image references. A mutable tag can select a snapshot built from an earlier image.
296
+ Snapshot creation requires available organization quota.
296
297
  Machine cleanup deletes the sandbox and retains the snapshot for reuse.
297
298
  The factory accepts `DaytonaNetworkPolicy` with `block_all`, `unrestricted`,
298
299
  `network_allow_list`, or `domain_allow_list`. The two allow-list modes require a
299
300
  `value`. Without a policy override, the factory uses `MachineSpec.network`.
300
- `MachineSpec.startup_timeout` bounds snapshot preparation and sandbox creation. Without
301
+ `MachineSpec.startup_timeout` bounds image preparation and sandbox creation. Without
301
302
  this value, the factory uses its `create_timeout` setting.
302
303
  Daytona gives stdout and stderr collection a shared 60-second deadline after a
303
304
  command exits. `DaytonaMachineFactory(output_collection_timeout=...)` changes
@@ -22,7 +22,7 @@ The base wheel contains the machine API and guest source. The [vendored Harbor p
22
22
 
23
23
  `factory.check_environment(requirements, spec)` checks task semantics, capabilities and software support before acquisition. Factories retain the requested `MachineSpec`; prepared images and bundles are backend inputs. The check does not promise available capacity or installed executables.
24
24
 
25
- The package provides a Harbor-independent machine interface. QEMU and Docker factories accept a registry reference or a local Dockerfile. QEMU also accepts a `PreparedImage` or a prebuilt guest bundle; Docker accepts a local image. `ShellSimMachineFactory` and `LocalMachineFactory` accept `PackageSpec(pypi_packages=..., tools=...)`; the local factory also accepts `HostImage()`, `PreparedImage` and registry references. Daytona accepts registry images and Dockerfiles at the build context root. Iris accepts registry image references. Local gVisor accepts the same images as Docker. Each `create` returns a fresh machine with a persistent writable filesystem. `run` returns bytes, exit status, and output truncation flags. `upload`, `download`, and `close` complete the common interface.
25
+ The package provides a Harbor-independent machine interface. QEMU and Docker factories accept a registry reference or a local Dockerfile. QEMU also accepts a `PreparedImage` or a prebuilt guest bundle; Docker accepts a local image. `ShellSimMachineFactory` and `LocalMachineFactory` accept `PackageSpec(pypi_packages=..., tools=...)`; the local factory also accepts `HostImage()`, `PreparedImage` and registry references. Daytona accepts registry images and Dockerfiles at the build context root. By default it builds each distinct image once into a reusable account snapshot; `DaytonaImageBuild.DECLARATIVE` builds the image for every sandbox instead and creates no snapshot. Iris accepts registry image references. Local gVisor accepts the same images as Docker. Each `create` returns a fresh machine with a persistent writable filesystem. `run` returns bytes, exit status, and output truncation flags. `upload`, `download`, and `close` complete the common interface.
26
26
 
27
27
  Shared contracts and OCI image preparation live at the package root. Backend machines live under `shellbox.backends.{qemu,shellsim,docker,gvisor,daytona,iris,local}`. Harbor owns the local, Daytona, QEMU and ShellSim environment adapters. Machines retain their runtime between commands; QEMU and ShellSim also support persistent Bash sessions.
28
28
 
@@ -268,15 +268,16 @@ Model commands that run as root can stop other root-owned processes.
268
268
 
269
269
  For Daytona, set `DAYTONA_API_KEY` and `DAYTONA_API_URL`. `DAYTONA_TARGET` is optional.
270
270
  Alternatively, supply a function that creates a configured `AsyncDaytona` client to `DaytonaMachineFactory`.
271
- Each machine owns and closes its client. The factory creates sandboxes from shared
272
- snapshots. Snapshot names derive from the registry reference or build-context contents
273
- and the requested resources. Use immutable image references. A mutable tag can
274
- select a snapshot built from an earlier image. Snapshot creation requires available organization quota.
271
+ Each machine owns and closes its client. In the default build mode, the factory
272
+ creates sandboxes from shared snapshots. Snapshot names derive from the registry
273
+ reference or build-context contents and the requested resources. Use immutable
274
+ image references. A mutable tag can select a snapshot built from an earlier image.
275
+ Snapshot creation requires available organization quota.
275
276
  Machine cleanup deletes the sandbox and retains the snapshot for reuse.
276
277
  The factory accepts `DaytonaNetworkPolicy` with `block_all`, `unrestricted`,
277
278
  `network_allow_list`, or `domain_allow_list`. The two allow-list modes require a
278
279
  `value`. Without a policy override, the factory uses `MachineSpec.network`.
279
- `MachineSpec.startup_timeout` bounds snapshot preparation and sandbox creation. Without
280
+ `MachineSpec.startup_timeout` bounds image preparation and sandbox creation. Without
280
281
  this value, the factory uses its `create_timeout` setting.
281
282
  Daytona gives stdout and stderr collection a shared 60-second deadline after a
282
283
  command exits. `DaytonaMachineFactory(output_collection_timeout=...)` changes
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "marin-shellbox"
7
- version = "0.2.282.dev43906453060"
7
+ version = "0.2.284.dev43909614052"
8
8
  description = "Shell execution machines with local and remote backends"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -12,11 +12,11 @@ dependencies = ["httpx>=0.27", "pydantic>=2.12,<3", "bubblewrap-bin==0.11.0; sys
12
12
 
13
13
  [project.optional-dependencies]
14
14
  qemu = ["quicksand-qemu>=0.5.12,<0.6"]
15
- shellsim = ["shellsim[pypi]>=0.1.38", "marin-rigging==0.2.282.dev43906453060"]
15
+ shellsim = ["shellsim[pypi]>=0.1.38", "marin-rigging==0.2.284.dev43909614052"]
16
16
  gvisor = []
17
- daytona = ["daytona==0.200.2", "marin-rigging==0.2.282.dev43906453060"]
17
+ daytona = ["daytona==0.200.2", "marin-rigging==0.2.284.dev43909614052"]
18
18
  iris = [
19
- "marin-iris==0.2.282.dev43906453060",
19
+ "marin-iris==0.2.284.dev43909614052",
20
20
  ]
21
21
 
22
22
  [project.scripts]
@@ -22,6 +22,7 @@ from pathlib import Path, PurePosixPath
22
22
  from daytona import (
23
23
  AsyncDaytona,
24
24
  AsyncSandbox,
25
+ CreateSandboxFromImageParams,
25
26
  CreateSandboxFromSnapshotParams,
26
27
  DaytonaConflictError,
27
28
  DaytonaNotFoundError,
@@ -31,6 +32,7 @@ from rigging.timing import ExponentialBackoff
31
32
 
32
33
  from shellbox.backends.daytona.process import DaytonaProcessSession
33
34
  from shellbox.backends.daytona.snapshot import (
35
+ daytona_image,
34
36
  ensure_snapshot,
35
37
  snapshot_request_for_spec,
36
38
  )
@@ -81,7 +83,9 @@ def _control_command(script: str) -> str:
81
83
  )
82
84
 
83
85
 
84
- async def _create_sandbox(client: AsyncDaytona, params: CreateSandboxFromSnapshotParams, timeout: float) -> AsyncSandbox:
86
+ async def _create_sandbox(
87
+ client: AsyncDaytona, params: CreateSandboxFromSnapshotParams | CreateSandboxFromImageParams, timeout: float
88
+ ) -> AsyncSandbox:
85
89
  """Retry throttling using a caller-owned name to recover an accepted creation."""
86
90
  assert params.name is not None
87
91
  backoff = ExponentialBackoff(initial=1, maximum=30, factor=2, jitter=0.5)
@@ -116,6 +120,19 @@ async def _delete_named_sandbox(client: AsyncDaytona, name: str) -> None:
116
120
  await client.delete(sandbox)
117
121
 
118
122
 
123
+ class DaytonaImageBuild(StrEnum):
124
+ """How a sandbox gets its image.
125
+
126
+ ``SNAPSHOT`` builds each distinct image once into a named account snapshot and starts
127
+ sandboxes from it; snapshots persist and count against the account's snapshot quota.
128
+ ``DECLARATIVE`` builds the image for every sandbox and creates no snapshot. The account
129
+ must permit declarative builds.
130
+ """
131
+
132
+ SNAPSHOT = "snapshot"
133
+ DECLARATIVE = "declarative"
134
+
135
+
119
136
  class DaytonaNetworkMode(StrEnum):
120
137
  BLOCK_ALL = "block_all"
121
138
  UNRESTRICTED = "unrestricted"
@@ -498,12 +515,14 @@ class DaytonaMachineFactory:
498
515
  create_timeout: float = 600,
499
516
  output_collection_timeout: float = DEFAULT_OUTPUT_COLLECTION_TIMEOUT,
500
517
  network_policy: DaytonaNetworkPolicy | None = None,
518
+ image_build: DaytonaImageBuild = DaytonaImageBuild.SNAPSHOT,
501
519
  ):
502
520
  self.client_factory = client_factory
503
521
  self.ttl_minutes = ttl_minutes
504
522
  self.create_timeout = create_timeout
505
523
  self.output_collection_timeout = output_collection_timeout
506
524
  self.network_policy = network_policy
525
+ self.image_build = image_build
507
526
 
508
527
  def _clients(self) -> Callable[[], AsyncDaytona]:
509
528
  """Resolve the configured client factory for one provider session."""
@@ -539,19 +558,19 @@ class DaytonaMachineFactory:
539
558
  image_reference=reference,
540
559
  )
541
560
 
542
- async def _prepare(self, client: AsyncDaytona, spec: MachineSpec) -> str:
543
- self._check_spec(spec)
544
- return await ensure_snapshot(client, snapshot_request_for_spec(spec))
545
-
546
561
  async def prepare(self, spec: MachineSpec) -> str:
547
562
  """Prepare the snapshot used by create without starting a sandbox.
548
563
 
549
564
  Pin registry sources by digest to reuse immutable image content.
550
565
  """
566
+ if self.image_build != DaytonaImageBuild.SNAPSHOT:
567
+ raise ValueError(f"{self.image_build} image builds create no snapshot to prepare")
551
568
  client_factory = self._clients()
552
569
  timeout = self.create_timeout if spec.startup_timeout is None else spec.startup_timeout
570
+ self._check_spec(spec)
571
+ request = snapshot_request_for_spec(spec)
553
572
  async with client_factory() as client, asyncio.timeout(timeout):
554
- return await self._prepare(client, spec)
573
+ return await ensure_snapshot(client, request)
555
574
 
556
575
  async def create(self, spec: MachineSpec) -> DaytonaMachine:
557
576
  network = (
@@ -563,21 +582,22 @@ class DaytonaMachineFactory:
563
582
  client = await lifetime.enter_async_context(self._clients()())
564
583
  timeout = self.create_timeout if spec.startup_timeout is None else spec.startup_timeout
565
584
  async with asyncio.timeout(timeout):
566
- snapshot = await self._prepare(client, spec)
585
+ self._check_spec(spec)
586
+ request = snapshot_request_for_spec(spec)
567
587
  name = f"shellbox-{uuid.uuid4().hex}"
568
- lifetime.push_async_callback(_delete_named_sandbox, client, name)
569
- sandbox = await _create_sandbox(
570
- client,
571
- CreateSandboxFromSnapshotParams(
572
- name=name,
573
- snapshot=snapshot,
574
- os_user="root",
575
- env_vars=spec.env,
576
- **network,
577
- ttl_minutes=self.ttl_minutes,
578
- ),
579
- timeout=timeout,
588
+ sandbox_fields = dict(
589
+ name=name, os_user="root", env_vars=spec.env, **network, ttl_minutes=self.ttl_minutes
580
590
  )
591
+ if self.image_build == DaytonaImageBuild.SNAPSHOT:
592
+ params = CreateSandboxFromSnapshotParams(
593
+ snapshot=await ensure_snapshot(client, request), **sandbox_fields
594
+ )
595
+ else:
596
+ params = CreateSandboxFromImageParams(
597
+ image=daytona_image(request.source), resources=request.resources, **sandbox_fields
598
+ )
599
+ lifetime.push_async_callback(_delete_named_sandbox, client, name)
600
+ sandbox = await _create_sandbox(client, params, timeout=timeout)
581
601
  prepared = await sandbox.process.exec(
582
602
  _control_command("command -v setsid"), cwd=CONTROL_CWD, timeout=INTERRUPT_TIMEOUT
583
603
  )
@@ -108,7 +108,7 @@ class SnapshotPurgeReport:
108
108
  def validate_source(
109
109
  source: RegistryImage | DockerfileSource,
110
110
  ) -> RegistryImage | DockerfileSource:
111
- """Reject Daytona build inputs it cannot snapshot."""
111
+ """Reject Daytona build inputs the provider cannot use."""
112
112
  if isinstance(source, RegistryImage):
113
113
  return source
114
114
  source = DockerfileSource(source.context.resolve(), source.dockerfile.resolve())
@@ -143,8 +143,13 @@ def snapshot_name(source: RegistryImage | DockerfileSource, resources: Resources
143
143
  return f"{SNAPSHOT_PREFIX}{hashlib.sha256(identity.encode()).hexdigest()[:40]}"
144
144
 
145
145
 
146
+ def daytona_image(source: RegistryImage | DockerfileSource) -> str | Image:
147
+ """Convert a validated source to the image argument Daytona builds from."""
148
+ return source.reference if isinstance(source, RegistryImage) else Image.from_dockerfile(source.dockerfile)
149
+
150
+
146
151
  def snapshot_request_for_spec(spec: MachineSpec) -> SnapshotRequest:
147
- """Derive the snapshot a machine spec will create."""
152
+ """Derive a machine spec's validated image source and provider resources."""
148
153
  source = spec.source
149
154
  if not isinstance(source, (RegistryImage, DockerfileSource)):
150
155
  raise UnsupportedMachineSpec("Daytona requires a registry image or Docker build context")
@@ -179,14 +184,9 @@ async def ensure_snapshot(client: AsyncDaytona, request: SnapshotRequest) -> str
179
184
  try:
180
185
  snapshot = await _snapshot_metadata(client, name)
181
186
  except DaytonaNotFoundError:
182
- image = (
183
- request.source.reference
184
- if isinstance(request.source, RegistryImage)
185
- else Image.from_dockerfile(request.source.dockerfile)
186
- )
187
187
  try:
188
188
  snapshot = await client.snapshot.create(
189
- CreateSnapshotParams(name=name, image=image, resources=request.resources)
189
+ CreateSnapshotParams(name=name, image=daytona_image(request.source), resources=request.resources)
190
190
  )
191
191
  except DaytonaConflictError:
192
192
  # Another rollout can create this image through a separate client.
@@ -27,14 +27,17 @@ pytest.importorskip("daytona")
27
27
 
28
28
  from daytona import (
29
29
  AsyncDaytona,
30
+ CreateSandboxFromImageParams,
30
31
  CreateSandboxFromSnapshotParams,
31
32
  DaytonaConfig,
32
33
  DaytonaNotFoundError,
34
+ Image,
33
35
  Resources,
34
36
  )
35
37
  from daytona_api_client_async import SnapshotState
36
38
  from shellbox.backends.daytona.connection import DaytonaConnection
37
39
  from shellbox.backends.daytona.machine import (
40
+ DaytonaImageBuild,
38
41
  DaytonaMachine,
39
42
  DaytonaMachineFactory,
40
43
  DaytonaNetworkMode,
@@ -229,8 +232,10 @@ class LocalDaytona:
229
232
  self.snapshot = LocalSnapshots()
230
233
 
231
234
  async def create(self, params, *, timeout):
232
- assert isinstance(params, CreateSandboxFromSnapshotParams)
233
- await self.snapshot.get(params.snapshot)
235
+ if isinstance(params, CreateSandboxFromSnapshotParams):
236
+ await self.snapshot.get(params.snapshot)
237
+ else:
238
+ assert isinstance(params, CreateSandboxFromImageParams)
234
239
  self.params = params
235
240
  self.timeout = timeout
236
241
  return self.sandbox
@@ -1038,15 +1043,49 @@ def test_daytona_reuses_snapshot_until_build_inputs_or_resources_change(tmp_path
1038
1043
  assert all(client.deleted and client.closed for client in clients)
1039
1044
 
1040
1045
 
1046
+ @pytest.mark.parametrize("image_build", list(DaytonaImageBuild))
1041
1047
  @pytest.mark.parametrize("instruction", ["ADD payload.tar /opt/", 'add ["payload.tar", "/opt/"]'])
1042
- def test_daytona_rejects_add_inputs_before_snapshot_creation(tmp_path, instruction):
1048
+ def test_daytona_rejects_add_inputs_before_building(tmp_path, instruction, image_build):
1043
1049
  dockerfile = tmp_path / "Dockerfile"
1044
1050
  dockerfile.write_text(f"FROM ubuntu:24.04\n{instruction}\n")
1045
1051
  (tmp_path / "payload.tar").write_bytes(b"archive fixture")
1046
1052
  client = LocalDaytona()
1053
+ factory = DaytonaMachineFactory(lambda: client, image_build=image_build)
1047
1054
  with pytest.raises(UnsupportedMachineSpec, match="ADD"):
1048
- asyncio.run(DaytonaMachineFactory(lambda: client).create(MachineSpec(DockerfileSource(tmp_path, dockerfile))))
1055
+ asyncio.run(factory.create(MachineSpec(DockerfileSource(tmp_path, dockerfile))))
1056
+ assert not client.snapshot.snapshots
1057
+ assert client.params is None
1058
+
1059
+
1060
+ @pytest.mark.parametrize("source_kind", ["registry", "dockerfile"])
1061
+ def test_declarative_build_starts_sandbox_from_image_without_snapshot(tmp_path, source_kind):
1062
+ context = tmp_path / "context"
1063
+ context.mkdir()
1064
+ dockerfile = context / "Dockerfile"
1065
+ dockerfile.write_text("FROM ubuntu:24.04\nRUN true\n")
1066
+ source = RegistryImage("ubuntu:24.04") if source_kind == "registry" else DockerfileSource(context, dockerfile)
1067
+ client = LocalDaytona()
1068
+ factory = DaytonaMachineFactory(lambda: client, image_build=DaytonaImageBuild.DECLARATIVE)
1069
+ spec = MachineSpec(source=source, workdir=str(tmp_path / "work"), cpus=4, memory_mb=8192, storage_mb=10240)
1070
+
1071
+ async def scenario():
1072
+ machine = await factory.create(spec)
1073
+ try:
1074
+ assert (await machine.run(Command(("printf", "ok")))).stdout == b"ok"
1075
+ finally:
1076
+ await machine.close()
1077
+
1078
+ asyncio.run(scenario())
1079
+ assert isinstance(client.params, CreateSandboxFromImageParams)
1080
+ if source_kind == "registry":
1081
+ assert client.params.image == "ubuntu:24.04"
1082
+ else:
1083
+ assert isinstance(client.params.image, Image)
1084
+ assert client.params.image.dockerfile() == dockerfile.read_text()
1085
+ resources = client.params.resources
1086
+ assert (resources.cpu, resources.memory, resources.disk) == (4, 8, 10)
1049
1087
  assert not client.snapshot.snapshots
1088
+ assert client.deleted and client.closed
1050
1089
 
1051
1090
 
1052
1091
  @pytest.mark.parametrize("invalid_source", ["add", "outside_context"])