langchain-prized 0.1.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.
- langchain_prized-0.1.0/.gitignore +5 -0
- langchain_prized-0.1.0/LICENSE +202 -0
- langchain_prized-0.1.0/PKG-INFO +182 -0
- langchain_prized-0.1.0/README.md +155 -0
- langchain_prized-0.1.0/langchain_prized/__init__.py +7 -0
- langchain_prized-0.1.0/langchain_prized/_api.py +1093 -0
- langchain_prized-0.1.0/langchain_prized/_version.py +3 -0
- langchain_prized-0.1.0/langchain_prized/provider.py +310 -0
- langchain_prized-0.1.0/langchain_prized/py.typed +0 -0
- langchain_prized-0.1.0/langchain_prized/sandbox.py +1251 -0
- langchain_prized-0.1.0/pyproject.toml +129 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: langchain-prized
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Prized Sandboxes (Firecracker microVMs) as a sandbox backend for LangChain Deep Agents
|
|
5
|
+
Project-URL: Homepage, https://prized.dev/sandboxes
|
|
6
|
+
Project-URL: Documentation, https://prized.dev/docs/sandboxes-langchain
|
|
7
|
+
Project-URL: API reference, https://prized.dev/docs/sandboxes-api
|
|
8
|
+
Author-email: Prized <team@prized.dev>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agents,code-execution,dcode,deep-agents,deepagents,firecracker,langchain,microvm,prized,sandbox
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: <4.0,>=3.11
|
|
24
|
+
Requires-Dist: deepagents<0.8.0,>=0.7.0
|
|
25
|
+
Requires-Dist: httpx<1.0.0,>=0.27.0
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# langchain-prized
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/langchain-prized/) [](https://pypi.org/project/langchain-prized/) [](https://pypi.org/project/langchain-prized/)
|
|
31
|
+
|
|
32
|
+
[Prized Sandboxes](https://prized.dev/docs/sandboxes) as a sandbox backend for [LangChain Deep Agents](https://docs.langchain.com/oss/python/deepagents/overview). Each sandbox is its own Firecracker microVM: it boots from a template, runs your agent's commands and file edits away from your machine, and can fork into live copies.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install langchain-prized
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Python 3.11 or later, with `deepagents` 0.7.
|
|
41
|
+
|
|
42
|
+
## Quickstart
|
|
43
|
+
|
|
44
|
+
For a Prized API key, [Open Sandboxes](https://prized.dev/onboarding/sandboxes) and choose **Create API key** (new to Prized, it signs you up with free credit, no card), or make one on the [API keys page](https://prized.dev/dashboard/workspace/api-keys) (Full access, or Custom with **Sandboxes: Write**). Export it with your model provider's key:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
export PRIZED_API_KEY=dcp_...
|
|
48
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from deepagents import create_deep_agent
|
|
53
|
+
from langchain_prized import PrizedSandbox
|
|
54
|
+
|
|
55
|
+
task = "Write fizzbuzz.py, run it, and show me the output."
|
|
56
|
+
with PrizedSandbox() as sandbox: # creates a sandbox, and deletes it on exit
|
|
57
|
+
agent = create_deep_agent(model="anthropic:claude-sonnet-5-5", backend=sandbox)
|
|
58
|
+
result = agent.invoke({"messages": [{"role": "user", "content": task}]})
|
|
59
|
+
print(result["messages"][-1].text)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The agent's `execute`, `read_file`, `write_file`, `edit_file`, `ls`, `glob`, and `grep` tools all run in the sandbox.
|
|
63
|
+
|
|
64
|
+
## Use it directly
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from langchain_prized import PrizedSandbox
|
|
68
|
+
|
|
69
|
+
sandbox = PrizedSandbox(template="prized-agent-v1", labels={"run": "pr-1874"})
|
|
70
|
+
try:
|
|
71
|
+
sandbox.upload_files([("/home/prized/work/app.py", b"print('hi')\n")])
|
|
72
|
+
result = sandbox.execute("python3 app.py | tee out.txt", timeout=600)
|
|
73
|
+
print(result.exit_code, result.output)
|
|
74
|
+
print(sandbox.download_files(["/home/prized/work/out.txt"])[0].content)
|
|
75
|
+
|
|
76
|
+
# Fork: live copies with this sandbox's memory, disk, and running processes.
|
|
77
|
+
children = sandbox.fork(3)
|
|
78
|
+
try:
|
|
79
|
+
for child in children:
|
|
80
|
+
print(child.id, child.execute("ls").output)
|
|
81
|
+
finally:
|
|
82
|
+
for child in children:
|
|
83
|
+
child.close() # deletes the child
|
|
84
|
+
finally:
|
|
85
|
+
sandbox.close() # deletes the sandbox
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The sandbox is created on first use (or by `start()`), and `close()` deletes it. If a create's answer is lost, the next `start()` gets the sandbox it made instead of making a second, and `close()` deletes it. To use one that already exists, pass `sandbox_id="sbx_..."`; it is left running on close unless you pass `delete_on_close=True`. `pause()` keeps memory and disk and stops compute billing; the next command or file transfer wakes it.
|
|
89
|
+
|
|
90
|
+
## Options
|
|
91
|
+
|
|
92
|
+
| Argument | Default | Meaning |
|
|
93
|
+
| --- | --- | --- |
|
|
94
|
+
| `template` | `prized-base-v1` | `prized-base-v1` (Ubuntu 24.04, Python 3, Node.js 22, build tools) or `prized-agent-v1` (adds Claude Code and Codex) |
|
|
95
|
+
| `api_key` | `PRIZED_API_KEY` | API key (`dcp_...`) |
|
|
96
|
+
| `api_url` | `PRIZED_API_URL`, else `https://api.prized.dev` | API origin |
|
|
97
|
+
| `vcpu`, `memory_mb`, `disk_gb` | The template's (4 vCPU, 8 GB, 10 GB) | Shape of a new sandbox, up to 32 vCPU, 128 GB of memory, and 128 GB of disk |
|
|
98
|
+
| `env_vars` | None | Variables for every command, stored encrypted |
|
|
99
|
+
| `labels` | None | Labels to filter on in the dashboard and API |
|
|
100
|
+
| `auto_pause_min`, `auto_delete_min`, `max_runtime_min` | Off, off, 1,440 (24 hours; 60 on the free tier) | Timers: pause when idle, delete when paused, delete after this many minutes of running (up to 10,080, 7 days) |
|
|
101
|
+
| `timeout` | 1800 | Default command timeout in seconds; at most 3600 |
|
|
102
|
+
| `cwd`, `env` | `/home/prized/work`, none | Defaults for every command |
|
|
103
|
+
| `sandbox_id` | None | Use an existing sandbox instead of creating one |
|
|
104
|
+
| `delete_on_close` | `True` if created here | Whether `close()` deletes the sandbox |
|
|
105
|
+
| `auto_resume` | `True` | A command or transfer wakes a paused sandbox. With `False` it stays paused: attaching raises `PrizedError` until `resume()`, and a command raises `sandbox_not_running` |
|
|
106
|
+
| `python_alias` | `True` | Put `python` (pointing at `python3`) on every command's PATH |
|
|
107
|
+
| `startup_timeout` | 180 | Seconds to wait for a create, resume, or pause to finish |
|
|
108
|
+
| `http_client` | None | An `httpx.Client` to send requests with (proxies); never closed by the backend |
|
|
109
|
+
|
|
110
|
+
`execute()` also takes `timeout`, `cwd`, and `env` per call. Its output is stdout, then stderr inside `<stderr>` tags; a timed-out command returns exit code 124.
|
|
111
|
+
|
|
112
|
+
## Inside a sandbox
|
|
113
|
+
|
|
114
|
+
- **User.** Commands run under `bash -c` as `prized`, without sudo, in `/home/prized/work` by default.
|
|
115
|
+
- **Files.** Any absolute path: files under `/home/prized` go through the files API, and others (such as `/tmp`) are staged under `/home/prized/.cache/langchain-prized` and put in place. Each file is written whole or not at all, so a write that fails (a full disk) leaves the old file, and a file it replaces keeps its mode, so a script you made executable stays executable. A symlink is written through: the file it points to changes and the link stays. Up to 100 MiB per file.
|
|
116
|
+
- **Output.** Each stream keeps its first 4 MiB; `truncated` is set past that.
|
|
117
|
+
- **Lost answers.** A command whose answer is lost is never sent again, and its `PrizedAPIError` says which of three it was: it never reached the sandbox, it may or may not have run, or it ran but the answer could not be read. A file goes up under a temporary name, sent again if need be, and one step that is never sent again puts it in place; a file's `error` says the same of that step.
|
|
118
|
+
- **Run time.** 24 hours of running by default, up to 7 days with `max_runtime_min`. On a paid workspace the clock stops while a sandbox is paused and starts again on every resume. A running sandbox you forget is deleted when its run time ends; a paused one is kept until you delete it (on the free tier, 30 days after its last use).
|
|
119
|
+
|
|
120
|
+
## Free tier
|
|
121
|
+
|
|
122
|
+
A new workspace gets free credit, and on the free credit alone sandboxes run within these limits ([Free tier](https://prized.dev/docs/sandboxes#free-tier)):
|
|
123
|
+
|
|
124
|
+
| Free tier | Limit |
|
|
125
|
+
| --- | --- |
|
|
126
|
+
| Sandboxes at once | 10; paused ones count toward the disk instead |
|
|
127
|
+
| Per sandbox | 2 vCPU and 4 GB of memory (a template's larger default is capped to this) |
|
|
128
|
+
| Across the workspace | 20 vCPU and 40 GB running, 100 GB of disk |
|
|
129
|
+
| Run time | 60 minutes of running in all; a larger `max_runtime_min` is refused. A paused sandbox is kept 30 days after its last use |
|
|
130
|
+
|
|
131
|
+
Past a limit the API answers `sandbox_quota_exceeded` or `invalid_resources`, raised as `PrizedAPIError` with `code`, `status`, and the answer's `body`. A plan or a top-up lifts the workspace to the full quotas.
|
|
132
|
+
|
|
133
|
+
## Deep Agents Code
|
|
134
|
+
|
|
135
|
+
With this package installed next to `deepagents-code`, `dcode --sandbox prized` runs the session in a new Prized sandbox; `--sandbox-id sbx_...` attaches to an existing one and leaves it running.
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
dcode install langchain-prized --package
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The provider reads these variables; a `DEEPAGENTS_CODE_` prefixed name wins over the plain one, as for dcode's own providers. The sandbox ones shape a new sandbox only.
|
|
142
|
+
|
|
143
|
+
| Variable | Default | Meaning |
|
|
144
|
+
| --- | --- | --- |
|
|
145
|
+
| `PRIZED_API_KEY` | None | API key (`dcp_...`), required |
|
|
146
|
+
| `PRIZED_API_URL` | `https://api.prized.dev` | API origin |
|
|
147
|
+
| `PRIZED_SANDBOX_TEMPLATE` | `prized-base-v1` | `prized-agent-v1` adds Claude Code and Codex |
|
|
148
|
+
| `PRIZED_SANDBOX_VCPU`, `PRIZED_SANDBOX_MEMORY_MB` | The template's | vCPUs, and memory in MiB |
|
|
149
|
+
| `PRIZED_SANDBOX_LABELS` | None | Labels, as `key=value,key=value` (a value may hold `=`, not `,`) |
|
|
150
|
+
| `PRIZED_SANDBOX_AUTO_PAUSE_MIN` | 15 | Pause after this many idle minutes; `0` is off. The session's next command wakes it |
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
PRIZED_SANDBOX_VCPU=2 PRIZED_SANDBOX_MEMORY_MB=4096 PRIZED_SANDBOX_LABELS=team=evals,session=s1 dcode --sandbox prized
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
To keep these settings in dcode's own config instead, declare the provider in `~/.deepagents/config.toml`. Its `params` (`template`, `vcpu`, `memory_mb`, `auto_pause_min`) win over the variables, and its `labels` are added to `PRIZED_SANDBOX_LABELS` (on a shared key, the config's wins). Keep `working_dir` as shown, since dcode tells the agent to work there.
|
|
157
|
+
|
|
158
|
+
```toml
|
|
159
|
+
[sandboxes.providers.prized]
|
|
160
|
+
class_path = "langchain_prized.provider:PrizedSandboxProvider"
|
|
161
|
+
working_dir = "/home/prized/work"
|
|
162
|
+
params = { template = "prized-agent-v1", vcpu = 2, memory_mb = 4096, auto_pause_min = 30, labels = { team = "evals" } }
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
As of `deepagents-code` 0.1.88, dcode does not delete the sandbox when the session ends. So a sandbox made for dcode pauses after 15 idle minutes by default: it keeps its memory and files and bills storage, not compute, and in a session still open the next command wakes it. A paused sandbox is kept until you delete it (on the free tier, 30 days after its last use), and its disk counts toward your workspace's disk quota; with `PRIZED_SANDBOX_AUTO_PAUSE_MIN=0` it runs instead, billing compute, until its run time ends (24 hours by default; 60 minutes on the free tier). Give each session its own label in `PRIZED_SANDBOX_LABELS`, as `session=s1` above, and delete its sandbox when you are done: `prized sandbox rm --label session=s1`, or `DELETE /api/v1/sandboxes?label=session=s1`. A label in `config.toml` is the same for every session, so deleting by it reaches the sandboxes of sessions still open.
|
|
166
|
+
|
|
167
|
+
## Development
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
uv sync
|
|
171
|
+
uv run pytest tests/unit_tests # offline, against a fake of the API
|
|
172
|
+
PRIZED_LIVE_TESTS=1 PRIZED_API_KEY=dcp_... uv run pytest tests/integration_tests # live
|
|
173
|
+
PRIZED_API_KEY=dcp_... uv run python scripts/live_smoke.py # live, a Deep Agent end to end, timed
|
|
174
|
+
uv run ruff check . && uv run ty check langchain_prized
|
|
175
|
+
uv run --group release python tests/package_check.py # the wheel and sdist as PyPI gets them
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
The unit tests include LangChain's standard sandbox suite, run against the fake; the integration tests run it against the live API. Reference: [Sandbox API](https://prized.dev/docs/sandboxes-api).
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
Apache-2.0. The full text is in the `LICENSE` file that ships with the package.
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# langchain-prized
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/langchain-prized/) [](https://pypi.org/project/langchain-prized/) [](https://pypi.org/project/langchain-prized/)
|
|
4
|
+
|
|
5
|
+
[Prized Sandboxes](https://prized.dev/docs/sandboxes) as a sandbox backend for [LangChain Deep Agents](https://docs.langchain.com/oss/python/deepagents/overview). Each sandbox is its own Firecracker microVM: it boots from a template, runs your agent's commands and file edits away from your machine, and can fork into live copies.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install langchain-prized
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Python 3.11 or later, with `deepagents` 0.7.
|
|
14
|
+
|
|
15
|
+
## Quickstart
|
|
16
|
+
|
|
17
|
+
For a Prized API key, [Open Sandboxes](https://prized.dev/onboarding/sandboxes) and choose **Create API key** (new to Prized, it signs you up with free credit, no card), or make one on the [API keys page](https://prized.dev/dashboard/workspace/api-keys) (Full access, or Custom with **Sandboxes: Write**). Export it with your model provider's key:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
export PRIZED_API_KEY=dcp_...
|
|
21
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from deepagents import create_deep_agent
|
|
26
|
+
from langchain_prized import PrizedSandbox
|
|
27
|
+
|
|
28
|
+
task = "Write fizzbuzz.py, run it, and show me the output."
|
|
29
|
+
with PrizedSandbox() as sandbox: # creates a sandbox, and deletes it on exit
|
|
30
|
+
agent = create_deep_agent(model="anthropic:claude-sonnet-5-5", backend=sandbox)
|
|
31
|
+
result = agent.invoke({"messages": [{"role": "user", "content": task}]})
|
|
32
|
+
print(result["messages"][-1].text)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The agent's `execute`, `read_file`, `write_file`, `edit_file`, `ls`, `glob`, and `grep` tools all run in the sandbox.
|
|
36
|
+
|
|
37
|
+
## Use it directly
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from langchain_prized import PrizedSandbox
|
|
41
|
+
|
|
42
|
+
sandbox = PrizedSandbox(template="prized-agent-v1", labels={"run": "pr-1874"})
|
|
43
|
+
try:
|
|
44
|
+
sandbox.upload_files([("/home/prized/work/app.py", b"print('hi')\n")])
|
|
45
|
+
result = sandbox.execute("python3 app.py | tee out.txt", timeout=600)
|
|
46
|
+
print(result.exit_code, result.output)
|
|
47
|
+
print(sandbox.download_files(["/home/prized/work/out.txt"])[0].content)
|
|
48
|
+
|
|
49
|
+
# Fork: live copies with this sandbox's memory, disk, and running processes.
|
|
50
|
+
children = sandbox.fork(3)
|
|
51
|
+
try:
|
|
52
|
+
for child in children:
|
|
53
|
+
print(child.id, child.execute("ls").output)
|
|
54
|
+
finally:
|
|
55
|
+
for child in children:
|
|
56
|
+
child.close() # deletes the child
|
|
57
|
+
finally:
|
|
58
|
+
sandbox.close() # deletes the sandbox
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The sandbox is created on first use (or by `start()`), and `close()` deletes it. If a create's answer is lost, the next `start()` gets the sandbox it made instead of making a second, and `close()` deletes it. To use one that already exists, pass `sandbox_id="sbx_..."`; it is left running on close unless you pass `delete_on_close=True`. `pause()` keeps memory and disk and stops compute billing; the next command or file transfer wakes it.
|
|
62
|
+
|
|
63
|
+
## Options
|
|
64
|
+
|
|
65
|
+
| Argument | Default | Meaning |
|
|
66
|
+
| --- | --- | --- |
|
|
67
|
+
| `template` | `prized-base-v1` | `prized-base-v1` (Ubuntu 24.04, Python 3, Node.js 22, build tools) or `prized-agent-v1` (adds Claude Code and Codex) |
|
|
68
|
+
| `api_key` | `PRIZED_API_KEY` | API key (`dcp_...`) |
|
|
69
|
+
| `api_url` | `PRIZED_API_URL`, else `https://api.prized.dev` | API origin |
|
|
70
|
+
| `vcpu`, `memory_mb`, `disk_gb` | The template's (4 vCPU, 8 GB, 10 GB) | Shape of a new sandbox, up to 32 vCPU, 128 GB of memory, and 128 GB of disk |
|
|
71
|
+
| `env_vars` | None | Variables for every command, stored encrypted |
|
|
72
|
+
| `labels` | None | Labels to filter on in the dashboard and API |
|
|
73
|
+
| `auto_pause_min`, `auto_delete_min`, `max_runtime_min` | Off, off, 1,440 (24 hours; 60 on the free tier) | Timers: pause when idle, delete when paused, delete after this many minutes of running (up to 10,080, 7 days) |
|
|
74
|
+
| `timeout` | 1800 | Default command timeout in seconds; at most 3600 |
|
|
75
|
+
| `cwd`, `env` | `/home/prized/work`, none | Defaults for every command |
|
|
76
|
+
| `sandbox_id` | None | Use an existing sandbox instead of creating one |
|
|
77
|
+
| `delete_on_close` | `True` if created here | Whether `close()` deletes the sandbox |
|
|
78
|
+
| `auto_resume` | `True` | A command or transfer wakes a paused sandbox. With `False` it stays paused: attaching raises `PrizedError` until `resume()`, and a command raises `sandbox_not_running` |
|
|
79
|
+
| `python_alias` | `True` | Put `python` (pointing at `python3`) on every command's PATH |
|
|
80
|
+
| `startup_timeout` | 180 | Seconds to wait for a create, resume, or pause to finish |
|
|
81
|
+
| `http_client` | None | An `httpx.Client` to send requests with (proxies); never closed by the backend |
|
|
82
|
+
|
|
83
|
+
`execute()` also takes `timeout`, `cwd`, and `env` per call. Its output is stdout, then stderr inside `<stderr>` tags; a timed-out command returns exit code 124.
|
|
84
|
+
|
|
85
|
+
## Inside a sandbox
|
|
86
|
+
|
|
87
|
+
- **User.** Commands run under `bash -c` as `prized`, without sudo, in `/home/prized/work` by default.
|
|
88
|
+
- **Files.** Any absolute path: files under `/home/prized` go through the files API, and others (such as `/tmp`) are staged under `/home/prized/.cache/langchain-prized` and put in place. Each file is written whole or not at all, so a write that fails (a full disk) leaves the old file, and a file it replaces keeps its mode, so a script you made executable stays executable. A symlink is written through: the file it points to changes and the link stays. Up to 100 MiB per file.
|
|
89
|
+
- **Output.** Each stream keeps its first 4 MiB; `truncated` is set past that.
|
|
90
|
+
- **Lost answers.** A command whose answer is lost is never sent again, and its `PrizedAPIError` says which of three it was: it never reached the sandbox, it may or may not have run, or it ran but the answer could not be read. A file goes up under a temporary name, sent again if need be, and one step that is never sent again puts it in place; a file's `error` says the same of that step.
|
|
91
|
+
- **Run time.** 24 hours of running by default, up to 7 days with `max_runtime_min`. On a paid workspace the clock stops while a sandbox is paused and starts again on every resume. A running sandbox you forget is deleted when its run time ends; a paused one is kept until you delete it (on the free tier, 30 days after its last use).
|
|
92
|
+
|
|
93
|
+
## Free tier
|
|
94
|
+
|
|
95
|
+
A new workspace gets free credit, and on the free credit alone sandboxes run within these limits ([Free tier](https://prized.dev/docs/sandboxes#free-tier)):
|
|
96
|
+
|
|
97
|
+
| Free tier | Limit |
|
|
98
|
+
| --- | --- |
|
|
99
|
+
| Sandboxes at once | 10; paused ones count toward the disk instead |
|
|
100
|
+
| Per sandbox | 2 vCPU and 4 GB of memory (a template's larger default is capped to this) |
|
|
101
|
+
| Across the workspace | 20 vCPU and 40 GB running, 100 GB of disk |
|
|
102
|
+
| Run time | 60 minutes of running in all; a larger `max_runtime_min` is refused. A paused sandbox is kept 30 days after its last use |
|
|
103
|
+
|
|
104
|
+
Past a limit the API answers `sandbox_quota_exceeded` or `invalid_resources`, raised as `PrizedAPIError` with `code`, `status`, and the answer's `body`. A plan or a top-up lifts the workspace to the full quotas.
|
|
105
|
+
|
|
106
|
+
## Deep Agents Code
|
|
107
|
+
|
|
108
|
+
With this package installed next to `deepagents-code`, `dcode --sandbox prized` runs the session in a new Prized sandbox; `--sandbox-id sbx_...` attaches to an existing one and leaves it running.
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
dcode install langchain-prized --package
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The provider reads these variables; a `DEEPAGENTS_CODE_` prefixed name wins over the plain one, as for dcode's own providers. The sandbox ones shape a new sandbox only.
|
|
115
|
+
|
|
116
|
+
| Variable | Default | Meaning |
|
|
117
|
+
| --- | --- | --- |
|
|
118
|
+
| `PRIZED_API_KEY` | None | API key (`dcp_...`), required |
|
|
119
|
+
| `PRIZED_API_URL` | `https://api.prized.dev` | API origin |
|
|
120
|
+
| `PRIZED_SANDBOX_TEMPLATE` | `prized-base-v1` | `prized-agent-v1` adds Claude Code and Codex |
|
|
121
|
+
| `PRIZED_SANDBOX_VCPU`, `PRIZED_SANDBOX_MEMORY_MB` | The template's | vCPUs, and memory in MiB |
|
|
122
|
+
| `PRIZED_SANDBOX_LABELS` | None | Labels, as `key=value,key=value` (a value may hold `=`, not `,`) |
|
|
123
|
+
| `PRIZED_SANDBOX_AUTO_PAUSE_MIN` | 15 | Pause after this many idle minutes; `0` is off. The session's next command wakes it |
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
PRIZED_SANDBOX_VCPU=2 PRIZED_SANDBOX_MEMORY_MB=4096 PRIZED_SANDBOX_LABELS=team=evals,session=s1 dcode --sandbox prized
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
To keep these settings in dcode's own config instead, declare the provider in `~/.deepagents/config.toml`. Its `params` (`template`, `vcpu`, `memory_mb`, `auto_pause_min`) win over the variables, and its `labels` are added to `PRIZED_SANDBOX_LABELS` (on a shared key, the config's wins). Keep `working_dir` as shown, since dcode tells the agent to work there.
|
|
130
|
+
|
|
131
|
+
```toml
|
|
132
|
+
[sandboxes.providers.prized]
|
|
133
|
+
class_path = "langchain_prized.provider:PrizedSandboxProvider"
|
|
134
|
+
working_dir = "/home/prized/work"
|
|
135
|
+
params = { template = "prized-agent-v1", vcpu = 2, memory_mb = 4096, auto_pause_min = 30, labels = { team = "evals" } }
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
As of `deepagents-code` 0.1.88, dcode does not delete the sandbox when the session ends. So a sandbox made for dcode pauses after 15 idle minutes by default: it keeps its memory and files and bills storage, not compute, and in a session still open the next command wakes it. A paused sandbox is kept until you delete it (on the free tier, 30 days after its last use), and its disk counts toward your workspace's disk quota; with `PRIZED_SANDBOX_AUTO_PAUSE_MIN=0` it runs instead, billing compute, until its run time ends (24 hours by default; 60 minutes on the free tier). Give each session its own label in `PRIZED_SANDBOX_LABELS`, as `session=s1` above, and delete its sandbox when you are done: `prized sandbox rm --label session=s1`, or `DELETE /api/v1/sandboxes?label=session=s1`. A label in `config.toml` is the same for every session, so deleting by it reaches the sandboxes of sessions still open.
|
|
139
|
+
|
|
140
|
+
## Development
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
uv sync
|
|
144
|
+
uv run pytest tests/unit_tests # offline, against a fake of the API
|
|
145
|
+
PRIZED_LIVE_TESTS=1 PRIZED_API_KEY=dcp_... uv run pytest tests/integration_tests # live
|
|
146
|
+
PRIZED_API_KEY=dcp_... uv run python scripts/live_smoke.py # live, a Deep Agent end to end, timed
|
|
147
|
+
uv run ruff check . && uv run ty check langchain_prized
|
|
148
|
+
uv run --group release python tests/package_check.py # the wheel and sdist as PyPI gets them
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
The unit tests include LangChain's standard sandbox suite, run against the fake; the integration tests run it against the live API. Reference: [Sandbox API](https://prized.dev/docs/sandboxes-api).
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
Apache-2.0. The full text is in the `LICENSE` file that ships with the package.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Prized Sandboxes as a sandbox backend for LangChain Deep Agents."""
|
|
2
|
+
|
|
3
|
+
from langchain_prized._api import PrizedAPIError, PrizedError
|
|
4
|
+
from langchain_prized._version import __version__
|
|
5
|
+
from langchain_prized.sandbox import PrizedSandbox
|
|
6
|
+
|
|
7
|
+
__all__ = ["PrizedAPIError", "PrizedError", "PrizedSandbox", "__version__"]
|