withruntime 0.5.0__tar.gz → 0.6.0__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 (116) hide show
  1. withruntime-0.6.0/LICENSE +55 -0
  2. {withruntime-0.5.0 → withruntime-0.6.0}/PKG-INFO +7 -3
  3. {withruntime-0.5.0 → withruntime-0.6.0}/README.md +3 -2
  4. {withruntime-0.5.0 → withruntime-0.6.0}/pyproject.toml +2 -1
  5. withruntime-0.6.0/tests/test_async_stream_cleanup.py +222 -0
  6. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_daytona.py +10 -0
  7. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_e2b_sandbox.py +7 -0
  8. withruntime-0.6.0/tests/test_files_mode.py +74 -0
  9. withruntime-0.6.0/tests/test_identity_token.py +104 -0
  10. withruntime-0.6.0/tests/test_mounts.py +69 -0
  11. withruntime-0.6.0/tests/test_network_funding.py +28 -0
  12. withruntime-0.6.0/tests/test_network_products.py +98 -0
  13. withruntime-0.6.0/tests/test_snapshot_after_fork.py +87 -0
  14. withruntime-0.6.0/tests/test_volume_backups.py +98 -0
  15. withruntime-0.6.0/tests/test_watch.py +144 -0
  16. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/__init__.py +43 -0
  17. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_async_client.py +91 -32
  18. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_async_products/__init__.py +10 -0
  19. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_async_products/desktop.py +61 -3
  20. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_async_products/interpreter.py +4 -2
  21. withruntime-0.6.0/withruntime/_async_products/mcp.py +64 -0
  22. withruntime-0.6.0/withruntime/_async_products/mounts.py +39 -0
  23. withruntime-0.6.0/withruntime/_async_products/network_products.py +154 -0
  24. withruntime-0.6.0/withruntime/_async_products/volumes.py +84 -0
  25. withruntime-0.6.0/withruntime/_async_products/watch.py +105 -0
  26. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_errors.py +2 -1
  27. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_http.py +62 -23
  28. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_sync_client.py +91 -32
  29. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_sync_products/__init__.py +10 -0
  30. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_sync_products/desktop.py +61 -3
  31. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_sync_products/interpreter.py +4 -2
  32. withruntime-0.6.0/withruntime/_sync_products/mcp.py +65 -0
  33. withruntime-0.6.0/withruntime/_sync_products/mounts.py +40 -0
  34. withruntime-0.6.0/withruntime/_sync_products/network_products.py +155 -0
  35. withruntime-0.6.0/withruntime/_sync_products/volumes.py +85 -0
  36. withruntime-0.6.0/withruntime/_sync_products/watch.py +106 -0
  37. withruntime-0.6.0/withruntime/_version.py +1 -0
  38. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/daytona/_async_daytona.py +5 -3
  39. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/daytona/_core.py +7 -0
  40. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/daytona/_sync_daytona.py +5 -3
  41. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/e2b/_async_sandbox.py +2 -2
  42. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/e2b/_core.py +7 -0
  43. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/e2b/_sync_sandbox.py +2 -2
  44. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime.egg-info/PKG-INFO +7 -3
  45. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime.egg-info/SOURCES.txt +18 -0
  46. withruntime-0.5.0/withruntime/_async_products/volumes.py +0 -43
  47. withruntime-0.5.0/withruntime/_sync_products/volumes.py +0 -44
  48. withruntime-0.5.0/withruntime/_version.py +0 -1
  49. {withruntime-0.5.0 → withruntime-0.6.0}/setup.cfg +0 -0
  50. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_audit.py +0 -0
  51. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_capacity_wait.py +0 -0
  52. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_client.py +0 -0
  53. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_deepagents.py +0 -0
  54. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_e2b_code_interpreter.py +0 -0
  55. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_images_v2.py +0 -0
  56. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_images_volumes_interpreter.py +0 -0
  57. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_lifecycle_settings.py +0 -0
  58. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_limits.py +0 -0
  59. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_observability.py +0 -0
  60. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_openai_agents.py +0 -0
  61. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_previews_network_desktop.py +0 -0
  62. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_proxy.py +0 -0
  63. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_referrals.py +0 -0
  64. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_secrets.py +0 -0
  65. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_switching.py +0 -0
  66. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_tools.py +0 -0
  67. {withruntime-0.5.0 → withruntime-0.6.0}/tests/test_vercel.py +0 -0
  68. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_async_products/audit.py +0 -0
  69. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_async_products/images.py +0 -0
  70. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_async_products/limits.py +0 -0
  71. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_async_products/network.py +0 -0
  72. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_async_products/observability.py +0 -0
  73. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_async_products/previews.py +0 -0
  74. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_async_products/referrals.py +0 -0
  75. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_async_products/secrets.py +0 -0
  76. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_async_products/switching.py +0 -0
  77. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_clock.py +0 -0
  78. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_connection.py +0 -0
  79. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_proxy.py +0 -0
  80. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_sync_products/audit.py +0 -0
  81. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_sync_products/images.py +0 -0
  82. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_sync_products/limits.py +0 -0
  83. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_sync_products/network.py +0 -0
  84. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_sync_products/observability.py +0 -0
  85. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_sync_products/previews.py +0 -0
  86. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_sync_products/referrals.py +0 -0
  87. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_sync_products/secrets.py +0 -0
  88. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_sync_products/switching.py +0 -0
  89. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_tunnel.py +0 -0
  90. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/_ws.py +0 -0
  91. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/daytona/__init__.py +0 -0
  92. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/daytona/_async_io.py +0 -0
  93. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/daytona/_sync_io.py +0 -0
  94. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/deepagents.py +0 -0
  95. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/e2b/__init__.py +0 -0
  96. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/e2b/_async_io.py +0 -0
  97. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/e2b/_sync_io.py +0 -0
  98. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/e2b/code_interpreter/__init__.py +0 -0
  99. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/e2b/code_interpreter/_async_ci.py +0 -0
  100. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/e2b/code_interpreter/_models.py +0 -0
  101. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/e2b/code_interpreter/_sync_ci.py +0 -0
  102. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/openai_agents.py +0 -0
  103. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/tools.py +0 -0
  104. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/vercel/__init__.py +0 -0
  105. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/vercel/_async_io.py +0 -0
  106. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/vercel/_async_sandbox.py +0 -0
  107. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/vercel/_core.py +0 -0
  108. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/vercel/_sync_io.py +0 -0
  109. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/vercel/_sync_sandbox.py +0 -0
  110. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/vercel/api.py +0 -0
  111. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/vercel/sandbox/__init__.py +0 -0
  112. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/vercel/sandbox/sync.py +0 -0
  113. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime/webhooks.py +0 -0
  114. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime.egg-info/dependency_links.txt +0 -0
  115. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime.egg-info/requires.txt +0 -0
  116. {withruntime-0.5.0 → withruntime-0.6.0}/withruntime.egg-info/top_level.txt +0 -0
@@ -0,0 +1,55 @@
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
+
17
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18
+
19
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20
+
21
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22
+
23
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24
+
25
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26
+
27
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28
+
29
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30
+
31
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34
+
35
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36
+
37
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
38
+
39
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
40
+
41
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
42
+
43
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
@@ -1,13 +1,16 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: withruntime
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: Runtime Cloud: one client (sync and async) for every Runtime product. Sandboxes first.
5
+ License: Apache-2.0
5
6
  Requires-Python: >=3.10
6
7
  Description-Content-Type: text/markdown
8
+ License-File: LICENSE
7
9
  Provides-Extra: openai-agents
8
10
  Requires-Dist: openai-agents>=0.22.3; extra == "openai-agents"
9
11
  Provides-Extra: deepagents
10
12
  Requires-Dist: deepagents>=0.7; extra == "deepagents"
13
+ Dynamic: license-file
11
14
 
12
15
  # Runtime Cloud Python SDK
13
16
 
@@ -37,6 +40,8 @@ with Sandbox.create() as sbx:
37
40
  `Sandbox.create()` needs no arguments and returns once the sandbox is running;
38
41
  leaving the `with` block stops it. With no arguments you get the free trial
39
42
  while it lasts: 50 free hours, no card, up to eight sandboxes running at once.
43
+ The current default image includes NumPy, pandas and matplotlib; see the
44
+ [sandbox environment](https://withruntime.com/docs/sandbox-environment).
40
45
  `AsyncRuntime` is the same client for asyncio, method for method:
41
46
 
42
47
  ```python
@@ -131,5 +136,4 @@ https://withruntime.com/docs/frameworks.
131
136
  Docs: https://withruntime.com/docs/python.
132
137
 
133
138
  The package was called `withruntime-cloud`, imported as `runtime_cloud`, until
134
- 0.3.0. Both names still work: `withruntime-cloud` installs this package and
135
- `import runtime_cloud` gives you the same classes.
139
+ 0.3.0. That name stopped at 0.5.1 and gets no new releases: use `withruntime`.
@@ -26,6 +26,8 @@ with Sandbox.create() as sbx:
26
26
  `Sandbox.create()` needs no arguments and returns once the sandbox is running;
27
27
  leaving the `with` block stops it. With no arguments you get the free trial
28
28
  while it lasts: 50 free hours, no card, up to eight sandboxes running at once.
29
+ The current default image includes NumPy, pandas and matplotlib; see the
30
+ [sandbox environment](https://withruntime.com/docs/sandbox-environment).
29
31
  `AsyncRuntime` is the same client for asyncio, method for method:
30
32
 
31
33
  ```python
@@ -120,5 +122,4 @@ https://withruntime.com/docs/frameworks.
120
122
  Docs: https://withruntime.com/docs/python.
121
123
 
122
124
  The package was called `withruntime-cloud`, imported as `runtime_cloud`, until
123
- 0.3.0. Both names still work: `withruntime-cloud` installs this package and
124
- `import runtime_cloud` gives you the same classes.
125
+ 0.3.0. That name stopped at 0.5.1 and gets no new releases: use `withruntime`.
@@ -4,9 +4,10 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "withruntime"
7
- version = "0.5.0"
7
+ version = "0.6.0"
8
8
  description = "Runtime Cloud: one client (sync and async) for every Runtime product. Sandboxes first."
9
9
  readme = "README.md"
10
+ license = { text = "Apache-2.0" }
10
11
  requires-python = ">=3.10"
11
12
  dependencies = []
12
13
 
@@ -0,0 +1,222 @@
1
+ """Real peer EOF proves stream/pool cleanup; a Python object disappearing does not."""
2
+ import asyncio
3
+ import unittest
4
+
5
+ from withruntime._async_client import _Transport
6
+
7
+
8
+ class AsyncStreamCleanupTest(unittest.IsolatedAsyncioTestCase):
9
+ async def asyncSetUp(self):
10
+ self.eof = asyncio.Event()
11
+ self.accepted = asyncio.Event()
12
+ self.writers = []
13
+ self.peer_eofs = []
14
+ self.responses = []
15
+ self.handlers = set()
16
+ self.body = b'{"event":1}\n{"event":2}\n'
17
+ self.partial = False
18
+ self.errors = []
19
+
20
+ async def answer(reader, writer):
21
+ task = asyncio.current_task()
22
+ self.handlers.add(task)
23
+ self.writers.append(writer)
24
+ peer_eof = asyncio.Event()
25
+ self.peer_eofs.append(peer_eof)
26
+ try:
27
+ await reader.readuntil(b'\r\n\r\n')
28
+ body = self.responses.pop(0) if self.responses else self.body
29
+ length = len(body) + (100 if self.partial else 0)
30
+ writer.write(b'HTTP/1.1 200 OK\r\nContent-Type: application/x-ndjson\r\nContent-Length: '
31
+ + str(length).encode() + b'\r\n\r\n' + body)
32
+ await writer.drain()
33
+ self.accepted.set()
34
+ await reader.read()
35
+ self.eof.set()
36
+ peer_eof.set()
37
+ except BaseException as error:
38
+ self.errors.append(error)
39
+ finally:
40
+ writer.close()
41
+ await writer.wait_closed()
42
+ self.handlers.discard(task)
43
+
44
+ self.server = await asyncio.start_server(answer, '127.0.0.1', 0)
45
+ self.transport = _Transport('fixture', f'http://127.0.0.1:{self.server.sockets[0].getsockname()[1]}', 5, 0)
46
+
47
+ async def asyncTearDown(self):
48
+ # Observe EOF before this fallback fixture cleanup, including on the
49
+ # unfixed implementation. Never count fixture shutdown as SDK cleanup.
50
+ await self.transport.close()
51
+ await asyncio.sleep(0)
52
+ await self.transport.close()
53
+ for writer in self.writers:
54
+ writer.close()
55
+ await writer.wait_closed()
56
+ self.server.close()
57
+ await self.server.wait_closed()
58
+ if self.handlers:
59
+ await asyncio.gather(*self.handlers)
60
+ self.assertEqual(self.errors, [])
61
+
62
+ async def assert_peer_closed(self):
63
+ await asyncio.wait_for(asyncio.gather(*(event.wait() for event in self.peer_eofs)), 0.5)
64
+ self.assertEqual(len(self.transport._http._idle), 0)
65
+
66
+ async def test_buffered_stream_close_then_transport_close_does_not_repool_later(self):
67
+ stream = self.transport.events('GET', '/events')
68
+ self.assertEqual(await anext(stream), {'event': 1})
69
+ await stream.aclose()
70
+ await self.transport.close()
71
+ await self.assert_peer_closed()
72
+ await asyncio.sleep(0)
73
+ self.assertEqual(len(self.transport._http._idle), 0)
74
+
75
+ async def test_partial_stream_close_immediately_closes_peer_without_pool_close(self):
76
+ self.partial = True
77
+ stream = self.transport.events('GET', '/events')
78
+ self.assertEqual(await anext(stream), {'event': 1})
79
+ await stream.aclose()
80
+ await self.assert_peer_closed()
81
+
82
+ async def test_json_decode_error_closes_partial_response(self):
83
+ self.body, self.partial = b'not-json\n', True
84
+ stream = self.transport.events('GET', '/events')
85
+ with self.assertRaises(ValueError):
86
+ await anext(stream)
87
+ await self.assert_peer_closed()
88
+
89
+ async def test_cancelled_pending_read_closes_peer(self):
90
+ self.body, self.partial = b'{"unfinished":', True
91
+ stream = self.transport.events('GET', '/events')
92
+ pending = asyncio.create_task(anext(stream))
93
+ await self.accepted.wait()
94
+ pending.cancel()
95
+ with self.assertRaises(asyncio.CancelledError):
96
+ await pending
97
+ await stream.aclose()
98
+ await self.assert_peer_closed()
99
+
100
+ async def test_completed_response_released_after_pool_close_is_not_kept(self):
101
+ response = await self.transport.send('GET', '/events')
102
+ self.assertEqual(await response._read_some(), self.body)
103
+ await self.transport.close()
104
+ await response.close()
105
+ await self.assert_peer_closed()
106
+
107
+ async def test_transport_close_closes_a_response_held_by_a_caller(self):
108
+ self.partial = True
109
+ response = await self.transport.send('GET', '/events')
110
+ await self.transport.close()
111
+ try:
112
+ await self.assert_peer_closed()
113
+ finally:
114
+ await response.close()
115
+
116
+ async def test_send_after_pool_close_never_opens_a_socket(self):
117
+ await self.transport.close()
118
+ with self.assertRaisesRegex(RuntimeError, "HTTP pool is closed"):
119
+ await self.transport.send('GET', '/events')
120
+ self.assertEqual(self.writers, [])
121
+
122
+
123
+ async def test_public_exec_stream_closes_partial_inner_stream_without_client_close(self):
124
+ from withruntime._async_client import AsyncSandbox
125
+ self.body = b'{"type":"stdout","offset":0,"data":"hello"}\n'
126
+ self.partial = True
127
+ retained = []
128
+ events = self.transport.events
129
+
130
+ def retain_stream(*args, **kwargs):
131
+ # Keep the inner iterator alive so this tests explicit ownership,
132
+ # not CPython's later async-generator finalizer scheduling.
133
+ stream = events(*args, **kwargs)
134
+ retained.append(stream)
135
+ return stream
136
+
137
+ self.transport.events = retain_stream
138
+ stream = AsyncSandbox(self.transport, {"id": "fixture"}).exec_stream(["echo", "hello"])
139
+ try:
140
+ self.assertEqual((await anext(stream))["data"], "hello")
141
+ await stream.aclose()
142
+ await self.assert_peer_closed()
143
+ finally:
144
+ await stream.aclose()
145
+ for inner in retained:
146
+ await inner.aclose()
147
+
148
+
149
+ async def test_public_process_output_and_exec_continuation_close_inner_streams(self):
150
+ from withruntime._async_client import AsyncProcess, AsyncSandbox
151
+ self.partial = True
152
+ self.body = b'{"type":"stdout","offset":0,"data":"hello"}\n'
153
+ retained = []
154
+ events = self.transport.events
155
+ def retain_stream(*args, **kwargs):
156
+ inner = events(*args, **kwargs)
157
+ retained.append(inner)
158
+ return inner
159
+ self.transport.events = retain_stream
160
+ for continuing in [False, True]:
161
+ if continuing:
162
+ self.responses = [b'{"type":"continue","processId":"process","cursor":0}\n', self.body]
163
+ stream = AsyncSandbox(self.transport, {"id":"fixture"}).exec_stream(["echo", "hello"])
164
+ else:
165
+ stream = AsyncProcess(self.transport, "fixture", {"id":"process"}).output()
166
+ try:
167
+ self.assertEqual((await anext(stream))["data"], "hello")
168
+ await stream.aclose()
169
+ await self.assert_peer_closed()
170
+ finally:
171
+ await stream.aclose()
172
+ for inner in retained:
173
+ await inner.aclose()
174
+ self.assertEqual(len(self.writers), 3)
175
+
176
+
177
+ class SyncStreamCleanupTest(unittest.TestCase):
178
+ def setUp(self):
179
+ import threading
180
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
181
+ from withruntime._sync_client import _Transport as SyncTransport
182
+ self.eof = threading.Event()
183
+ eof = self.eof
184
+ body = b'{"event":1}\n{"event":2}\n'
185
+
186
+ class Handler(BaseHTTPRequestHandler):
187
+ protocol_version = 'HTTP/1.1'
188
+ def log_message(self, *args):
189
+ pass
190
+ def do_GET(self):
191
+ self.send_response(200)
192
+ self.send_header('Content-Length', str(len(body)))
193
+ self.end_headers()
194
+ self.wfile.write(body)
195
+ self.wfile.flush()
196
+ if self.rfile.read(1) == b'':
197
+ eof.set()
198
+
199
+ self.server = ThreadingHTTPServer(('127.0.0.1', 0), Handler)
200
+ self.thread = threading.Thread(target=self.server.serve_forever)
201
+ self.thread.start()
202
+ self.transport = SyncTransport('fixture', f'http://127.0.0.1:{self.server.server_port}', 5, 0)
203
+
204
+ def tearDown(self):
205
+ self.transport.close()
206
+ self.server.shutdown()
207
+ self.server.server_close()
208
+ self.thread.join()
209
+
210
+ def test_generator_close_closes_unread_response_without_pool_close(self):
211
+ stream = self.transport.events('GET', '/events')
212
+ self.assertEqual(next(stream), {'event': 1})
213
+ stream.close()
214
+ self.assertTrue(self.eof.wait(0.5), 'SDK did not close the peer before fixture cleanup')
215
+
216
+ def test_late_response_close_cannot_refill_closed_sync_pool(self):
217
+ response = self.transport.send('GET', '/events')
218
+ response._response.read()
219
+ self.transport.close()
220
+ response.close()
221
+ self.assertTrue(self.eof.wait(0.5), 'closed pool retained a late response')
222
+ self.assertEqual(self.transport._http._idle.qsize(), 0)
@@ -159,6 +159,16 @@ class Process(Base):
159
159
  self.assertEqual(command, "{ ls\n} 2>&1")
160
160
  self.assertEqual(options, {"cwd": "/workspace/src", "env": {"A": "1", "B": "2"}, "timeout_ms": 5000})
161
161
 
162
+ def test_whole_output_past_the_64_kib_an_exec_result_holds(self):
163
+ big = "x" * 70_000 + "\n"
164
+ self.world.exec = lambda command, _: (Result(0, "/workspace/a.py:1:x\n" * 4_000)
165
+ if str(command).startswith("['grep'") else Result(0, big))
166
+ sandbox = self.daytona.create()
167
+ # A timeout of a minute or less is an exec that is not otherwise streamed.
168
+ self.assertEqual(sandbox.process.exec("cat big", timeout=30).result, big)
169
+ self.assertEqual(sandbox.process.code_run("print('x'*70000)", timeout=30).result, big)
170
+ self.assertEqual(len(sandbox.fs.find_files(".", "x")), 4_000)
171
+
162
172
  def test_timeout(self):
163
173
  self.world.exec = lambda command, _: Result(None, timed_out=True)
164
174
  sandbox = self.daytona.create()
@@ -138,6 +138,13 @@ class Commands(Base):
138
138
  self.assertEqual(self.world.called("sandbox.exec")[-1],
139
139
  ("echo hi", {"cwd": "/tmp", "env": {"A": "1", "B": "3"}, "timeout_ms": 60_000}))
140
140
 
141
+ def test_whole_output_past_the_64_kib_an_exec_result_holds(self):
142
+ # The judge panel's reproduction: python3 -c 'print("x"*70000)'.
143
+ self.world.exec = lambda *_: Result(0, "x" * 70_000 + "\n", "y" * 70_000)
144
+ sbx = self.create()
145
+ result = sbx.commands.run("python3 -c 'print(\"x\"*70000)'", timeout=60)
146
+ self.assertEqual((result.exit_code, len(result.stdout), len(result.stderr)), (0, 70_001, 70_000))
147
+
141
148
  def test_non_zero_exit(self):
142
149
  self.world.exec = lambda *_: Result(3, "partial\n", "boom\n")
143
150
  sbx = self.create()
@@ -0,0 +1,74 @@
1
+ """Both client forms preserve mode on current and legacy guests."""
2
+ import asyncio
3
+ import unittest
4
+ from withruntime._async_client import AsyncFiles
5
+ from withruntime._sync_client import Files
6
+ from withruntime._errors import RuntimeError
7
+
8
+
9
+ class Transport:
10
+ def __init__(self, kind):
11
+ self.kind, self.calls = kind, []
12
+
13
+ def json(self, method, path, body):
14
+ self.calls.append((path, body))
15
+ if path.endswith('/uploads'):
16
+ if self.kind == 'denied' or self.kind == 'legacy' and body.get('mode'):
17
+ raise RuntimeError('fixture', code='forbidden' if self.kind == 'denied' else 'guest_upgrade_required')
18
+ return {'uploadId': 'upload', 'chunkBytes': 1048576, **({'mode': body.get('mode')} if self.kind == 'modern' else {})}
19
+ return {}
20
+
21
+ def send(self, method, path, **kwargs):
22
+ self.calls.append((path, kwargs))
23
+ return self
24
+
25
+ def read(self):
26
+ return b''
27
+
28
+
29
+ class AsyncTransport(Transport):
30
+ async def json(self, *args, **kwargs):
31
+ return super().json(*args, **kwargs)
32
+
33
+ async def send(self, *args, **kwargs):
34
+ return super().send(*args, **kwargs)
35
+
36
+ async def read(self):
37
+ return b''
38
+
39
+
40
+ class FileModes(unittest.TestCase):
41
+ def check_calls(self, kind, calls):
42
+ begins = [body for path, body in calls if path.endswith('/uploads')]
43
+ self.assertEqual(len(begins), 2 if kind == 'legacy' else 1)
44
+ self.assertEqual(len([path for path, _ in calls if path.endswith('/files:chmod')]), 0 if kind == 'modern' else 1)
45
+ if kind == 'legacy':
46
+ self.assertNotIn('mode', begins[1])
47
+
48
+ def test_sync_current_legacy_old_api(self):
49
+ for kind in ('modern', 'legacy', 'old-api'):
50
+ with self.subTest(kind=kind):
51
+ transport = Transport(kind)
52
+ Files(transport, 'sandbox').write('/workspace/run', b'x' * 1048577, mode=0o755)
53
+ self.check_calls(kind, transport.calls)
54
+
55
+ def test_async_current_legacy_old_api(self):
56
+ async def run():
57
+ for kind in ('modern', 'legacy', 'old-api'):
58
+ with self.subTest(kind=kind):
59
+ transport = AsyncTransport(kind)
60
+ await AsyncFiles(transport, 'sandbox').write('/workspace/run', b'x' * 1048577, mode=0o755)
61
+ self.check_calls(kind, transport.calls)
62
+ asyncio.run(run())
63
+
64
+ def test_other_refusals_do_not_retry(self):
65
+ transport = Transport('denied')
66
+ with self.assertRaises(RuntimeError):
67
+ Files(transport, 'sandbox').write('/workspace/run', b'x' * 1048577, mode=0o755)
68
+ self.assertEqual(len(transport.calls), 1)
69
+ async def run():
70
+ transport = AsyncTransport('denied')
71
+ with self.assertRaises(RuntimeError):
72
+ await AsyncFiles(transport, 'sandbox').write('/workspace/run', b'x' * 1048577, mode=0o755)
73
+ self.assertEqual(len(transport.calls), 1)
74
+ asyncio.run(run())
@@ -0,0 +1,104 @@
1
+ """Sandbox.identity_token() against a stub of /v1/identity/token: the request
2
+ token from the environment as the bearer, the audience and lifetime in the
3
+ query, the token back. The route itself is tested in packages/cloud
4
+ (identity-tokens.test.ts)."""
5
+ import json
6
+ import os
7
+ import threading
8
+ import unittest
9
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
10
+ from urllib.parse import parse_qs, urlparse
11
+
12
+ from withruntime import RuntimeError, Sandbox
13
+
14
+
15
+ class Stub(BaseHTTPRequestHandler):
16
+ seen: list = []
17
+
18
+ def log_message(self, *args):
19
+ pass
20
+
21
+ def do_GET(self):
22
+ url = urlparse(self.path)
23
+ Stub.seen.append((url.path, parse_qs(url.query), self.headers.get("Authorization")))
24
+ if self.headers.get("Authorization") != "Bearer rtid1.statement.sig":
25
+ body, status = {"error": {"code": "unauthorized", "message": "This request token is not valid."}}, 401
26
+ else:
27
+ body, status = {"token": "header.payload.signature", "expiresAt": "2026-09-24T00:10:00Z"}, 200
28
+ data = json.dumps(body).encode()
29
+ self.send_response(status)
30
+ self.send_header("Content-Type", "application/json")
31
+ self.send_header("Content-Length", str(len(data)))
32
+ self.end_headers()
33
+ self.wfile.write(data)
34
+
35
+
36
+ class IdentityTokenTest(unittest.TestCase):
37
+ def setUp(self):
38
+ self.server = ThreadingHTTPServer(("127.0.0.1", 0), Stub)
39
+ self.thread = threading.Thread(target=self.server.serve_forever, daemon=True)
40
+ self.thread.start()
41
+ self.saved = {k: os.environ.get(k) for k in ("RUNTIME_ID_TOKEN_REQUEST_URL", "RUNTIME_ID_TOKEN_REQUEST_TOKEN")}
42
+ os.environ["RUNTIME_ID_TOKEN_REQUEST_URL"] = f"http://127.0.0.1:{self.server.server_port}/v1/identity/token"
43
+ Stub.seen = []
44
+
45
+ def tearDown(self):
46
+ self.server.shutdown()
47
+ self.server.server_close()
48
+ self.thread.join()
49
+ self.assertEqual(self.server.fileno(), -1, "fixture listener was not closed")
50
+ for key, value in self.saved.items():
51
+ if value is None:
52
+ os.environ.pop(key, None)
53
+ else:
54
+ os.environ[key] = value
55
+
56
+ def test_asks_with_the_sandbox_request_token_for_the_audience(self):
57
+ os.environ["RUNTIME_ID_TOKEN_REQUEST_TOKEN"] = "rtid1.statement.sig"
58
+ token = Sandbox.identity_token("sts.amazonaws.com", lifetime_seconds=900)
59
+ self.assertEqual(token, "header.payload.signature")
60
+ path, query, auth = Stub.seen[0]
61
+ self.assertEqual(path, "/v1/identity/token")
62
+ self.assertEqual(query, {"audience": ["sts.amazonaws.com"], "lifetimeSeconds": ["900"]})
63
+ self.assertEqual(auth, "Bearer rtid1.statement.sig")
64
+
65
+ def test_a_refusal_carries_the_api_message(self):
66
+ os.environ["RUNTIME_ID_TOKEN_REQUEST_TOKEN"] = "rtid1.other.sig"
67
+ import urllib.error
68
+ import urllib.request
69
+ from unittest.mock import patch
70
+ urlopen = urllib.request.urlopen
71
+ responses = []
72
+
73
+ def record_error(*args, **kwargs):
74
+ try:
75
+ return urlopen(*args, **kwargs)
76
+ except urllib.error.HTTPError as error:
77
+ responses.append(error)
78
+ raise
79
+
80
+ try:
81
+ with patch("urllib.request.urlopen", side_effect=record_error):
82
+ with self.assertRaises(RuntimeError) as caught:
83
+ Sandbox.identity_token("sts.amazonaws.com")
84
+ self.assertIn("not valid", str(caught.exception))
85
+ self.assertEqual(caught.exception.status, 401)
86
+ self.assertEqual(len(responses), 1)
87
+ self.assertTrue(responses[0].closed, "identity error response was not closed")
88
+ finally:
89
+ # Preserve deterministic cleanup even against the unfixed client;
90
+ # the assertion above observes SDK ownership, before this fallback.
91
+ for response in responses:
92
+ response.close()
93
+
94
+ def test_outside_a_sandbox_there_is_nothing_to_ask_with(self):
95
+ os.environ.pop("RUNTIME_ID_TOKEN_REQUEST_TOKEN", None)
96
+ if os.path.exists("/run/runtime/environment.json"):
97
+ self.skipTest("running inside a sandbox")
98
+ with self.assertRaises(RuntimeError) as caught:
99
+ Sandbox.identity_token("sts.amazonaws.com")
100
+ self.assertEqual(caught.exception.code, "identity_unavailable")
101
+
102
+
103
+ if __name__ == "__main__":
104
+ unittest.main()
@@ -0,0 +1,69 @@
1
+ """Bucket mounts from the Python SDK against a stub API: the paths and bodies
2
+ sbx.mounts sends. The route is tested in packages/cloud (mounts-api)."""
3
+ import json
4
+ import threading
5
+ import unittest
6
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
7
+ from urllib.parse import urlsplit
8
+
9
+ from withruntime import Runtime
10
+
11
+ SANDBOX = "11111111-2222-4333-8444-555555555555"
12
+
13
+
14
+ class Stub(BaseHTTPRequestHandler):
15
+ seen: list = []
16
+
17
+ def log_message(self, *args):
18
+ pass
19
+
20
+ def _reply(self, value):
21
+ data = json.dumps(value).encode()
22
+ self.send_response(200)
23
+ self.send_header("content-type", "application/json")
24
+ self.send_header("content-length", str(len(data)))
25
+ self.end_headers()
26
+ self.wfile.write(data)
27
+
28
+ def _route(self):
29
+ url = urlsplit(self.path)
30
+ length = int(self.headers.get("content-length") or 0)
31
+ body = json.loads(self.rfile.read(length)) if length else None
32
+ Stub.seen.append((self.command, url.path, body))
33
+ if url.path.endswith("/mounts") and self.command == "POST":
34
+ return self._reply({**body, "mounted": True})
35
+ if url.path.endswith("/mounts"):
36
+ return self._reply({"data": [{"path": "/data", "mounted": True}]})
37
+ if url.path.endswith("/mounts:unmount"):
38
+ return self._reply({"path": body["path"], "mounted": False})
39
+ return self._reply({"id": SANDBOX, "state": "running", "status": "active"})
40
+
41
+ do_GET = do_POST = _route
42
+
43
+
44
+ class Mounts(unittest.TestCase):
45
+ @classmethod
46
+ def setUpClass(cls):
47
+ cls.server = ThreadingHTTPServer(("127.0.0.1", 0), Stub)
48
+ threading.Thread(target=cls.server.serve_forever, daemon=True).start()
49
+ cls.url = f"http://127.0.0.1:{cls.server.server_address[1]}"
50
+
51
+ @classmethod
52
+ def tearDownClass(cls):
53
+ cls.server.shutdown()
54
+
55
+ def test_add_list_remove(self):
56
+ runtime = Runtime(api_key="rk_test", base_url=self.url, max_retries=0)
57
+ sbx = runtime.sandboxes.get(SANDBOX)
58
+ made = sbx.mounts.add(provider="r2", bucket="assets", path="/assets", account_id="a" * 32,
59
+ secret="R2_KEYS", read_only=True)
60
+ self.assertTrue(made["mounted"])
61
+ self.assertEqual(Stub.seen[-1], ("POST", f"/v1/sandboxes/{SANDBOX}/mounts", {
62
+ "provider": "r2", "bucket": "assets", "path": "/assets", "accountId": "a" * 32,
63
+ "secret": "R2_KEYS", "readOnly": True}))
64
+ self.assertEqual([m["path"] for m in sbx.mounts.list()], ["/data"])
65
+ self.assertEqual(sbx.mounts.remove("/assets"), {"path": "/assets", "mounted": False})
66
+
67
+
68
+ if __name__ == "__main__":
69
+ unittest.main()
@@ -0,0 +1,28 @@
1
+ """Funding is retained on sync/async network results, and reflected in public types."""
2
+ import asyncio
3
+ import unittest
4
+ from withruntime._sync_products.network_products import Addresses, Tunnel, AddressResult, TunnelResult
5
+ from withruntime._async_products.network_products import AsyncAddresses, AsyncTunnel
6
+
7
+ VALUE = {"id":"reservation", "funded":False,"fundedUntil":"2026-09-24T00:00:00.000Z","rateMicros":5000000,"rateUnit":"unit_month"}
8
+ class SyncTransport:
9
+ def json(self, method, path, **kwargs):
10
+ return {"data":[VALUE]} if path == '/v1/addresses' and method == 'GET' else VALUE
11
+ class AsyncTransport:
12
+ async def json(self, method, path, **kwargs):
13
+ return SyncTransport().json(method,path,**kwargs)
14
+ class Funding(unittest.TestCase):
15
+ def test_sync_and_types(self):
16
+ self.assertEqual(Addresses(SyncTransport()).reserve(),VALUE)
17
+ self.assertEqual(Addresses(SyncTransport()).list(),[VALUE])
18
+ self.assertEqual(Tunnel(SyncTransport()).get(),VALUE)
19
+ for kind in [AddressResult,TunnelResult]:
20
+ for field in ['funded','fundedUntil','rateMicros','rateUnit']:
21
+ self.assertIn(field,kind.__annotations__)
22
+ def test_async(self):
23
+ async def run():
24
+ self.assertEqual(await AsyncAddresses(AsyncTransport()).reserve(),VALUE)
25
+ self.assertEqual(await AsyncAddresses(AsyncTransport()).list(),[VALUE])
26
+ self.assertEqual(await AsyncTunnel(AsyncTransport()).get(),VALUE)
27
+ asyncio.run(run())
28
+ if __name__=='__main__': unittest.main()