agentrun-plus 0.2.6__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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2024 Jonathan Adly
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,392 @@
1
+ Metadata-Version: 2.4
2
+ Name: agentrun_plus
3
+ Version: 0.2.6
4
+ Summary: The easiest way to run AI or user generated python code safely in a docker container. This is a fork of the original AgentRun repo with additional customization options added.
5
+ Author-email: Jonathan Adly <gadly0123@gmail.com>, Vijay Ramasami <rvijayc@gmail.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/rvijayc/AgentRun
8
+ Project-URL: Changelog, https://github.com/rvijayc/AgentRun/releases
9
+ Project-URL: Issues, https://github.com/rvijayc/AgentRun/issues
10
+ Project-URL: CI, https://github.com/rvijayc/AgentRun/actions
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: docker
16
+ Requires-Dist: RestrictedPython
17
+ Requires-Dist: loguru
18
+ Provides-Extra: test
19
+ Requires-Dist: pytest; extra == "test"
20
+ Requires-Dist: pytest-cov; extra == "test"
21
+ Requires-Dist: pytest-benchmark; extra == "test"
22
+ Requires-Dist: mypy; extra == "test"
23
+ Requires-Dist: mkdocs; extra == "test"
24
+ Requires-Dist: mkdocs-material; extra == "test"
25
+ Requires-Dist: mkdocstrings[python]; extra == "test"
26
+ Requires-Dist: mkdocs-jupyter; extra == "test"
27
+ Dynamic: license-file
28
+
29
+ # AgentRun: Run AI Generated Code Safely
30
+
31
+ [![PyPI](https://img.shields.io/pypi/v/agentrun.svg)](https://pypi.org/project/agentrun/)
32
+ [![Tests](https://github.com/jonathan-adly/agentrun/actions/workflows/test.yml/badge.svg)](https://github.com/jonathan-adly/agentrun/actions/workflows/test.yml)
33
+ [![Changelog](https://img.shields.io/github/v/release/jonathan-adly/agentrun?include_prereleases&label=changelog)](https://github.com/jonathan-adly/agentrun/releases)
34
+ ![PyPI - Downloads](https://img.shields.io/pypi/dm/agentrun)
35
+ ![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2FJonathan-Adly%2FAgentRun%2Fdevelop%2Fpyproject.toml)
36
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/jonathan-adly/agentrun/blob/main/LICENSE)
37
+ [![MkDocs](https://img.shields.io/badge/MkDocs-526CFE?logo=materialformkdocs&logoColor=fff)](https://jonathan-adly.github.io/AgentRun/)
38
+ [![Twitter Follow](https://img.shields.io/twitter/follow/Jonathan_Adly_?style=social)](https://twitter.com/Jonathan_Adly_)
39
+
40
+ >> This is a fork of the AgentRun library that has some added customizations and optimizations, specifically:
41
+ >>
42
+ >> - Customize Install Commands.
43
+ >> - Fixed issues with "uv" installer.
44
+ >> - Improved management of cached dependencies.
45
+ >> - Option to allow certain unsafe functions (due to false positives).
46
+ >> - Option to ignore certain dependencies.
47
+
48
+ AgentRun is a Python library that makes it easy to run Python code safely from large language models (LLMs) with a single line of code. Built on top of the Docker Python SDK and RestrictedPython, it provides a simple, transparent, and user-friendly API to manage isolated code execution.
49
+
50
+ AgentRun automatically installs and uninstalls dependencies with optional caching, limits resource consumption, checks code safety, and sets execution timeouts. It has 97% test coverage with full static typing and only two dependencies.
51
+
52
+ - [Documentation](https://jonathan-adly.github.io/AgentRun/)
53
+
54
+ - [Get started in minutes](#getting-started)
55
+
56
+ > [!NOTE]
57
+ > Looking for a state of the art RAG API? Check out [ColiVara](https://github.com/tjmlabs/ColiVara), also from us.
58
+
59
+ ## Why?
60
+
61
+ Giving code execution ability to LLMs is a massive upgrade. Consider the following user query: `what is 12345 * 54321?` or even something more ambitious like `what is the average daily move of Apple stock during the last week?`? With code execution it is possible for LLMs to answer both accurately by executing code.
62
+
63
+ However, executing untrusted code is dangerous and full of potential footguns. For instance, without proper safeguards, an LLM might generate harmful code like this:
64
+
65
+ ```python
66
+ import os
67
+ # deletes all files and directories
68
+ os.system('rm -rf /')
69
+ ```
70
+
71
+ This package gives code execution ability to **any LLM** in a single line of code, while preventing and guarding against dangerous code.
72
+
73
+
74
+ ## Key Features
75
+
76
+ - **Safe code execution**: AgentRun checks the generated code for dangerous elements before execution
77
+ - **Isolated Environment**: Code is executed in a fully isolated docker container
78
+ - **Configurable Resource Management**: You can set how much compute resources the code can consume, with sane defaults
79
+ - **Timeouts**: Set time limits on how long a script can take to run
80
+ - **Dependency Management**: Complete control on what dependencies are allowed to install
81
+ - **Dependency Caching**: AgentRun gives you the ability to cache any dependency in advance in the docker container to optimize performance.
82
+ - **Automatic Cleanups**: AgentRun cleans any artifacts created by the generated code.
83
+ - **Comes with a REST API**: Hate setting up docker? AgentRun comes with already configured docker setup for self-hosting.
84
+ - **Transparent Exception Handling**: AgentRun returns the same exact output as running Python in your system - exceptions and tracebacks included. No cryptic docker messages.
85
+
86
+ If you want to use your own Docker configuration, install this package with pip and simply initialize AgentRun with a running Docker container. Additionally, you can use an already configured Docker Compose setup and API that is ready for self-hosting by cloning this repo.
87
+
88
+ Unless you are comfortable with Docker, **we highly recommend using the REST API with the already configured Docker as a standalone service.**
89
+
90
+
91
+ ## Getting Started
92
+
93
+ There are two ways to use AgentRun, depending on your needs: with pip for your own Docker setup, or directly as a REST API as a standalone service (recommended).
94
+
95
+ ### REST API
96
+
97
+ Clone the github repository and start immediately with a standalone REST API.
98
+
99
+ ```bash
100
+ git clone https://github.com/Jonathan-Adly/agentrun
101
+ cd agentrun/agentrun-api
102
+ cp .env.example .env.dev
103
+ docker-compose up -d --build
104
+ ```
105
+
106
+ Then - you have a fully up and running code execution API. *Code in --> output out*
107
+
108
+ ```javascript
109
+ fetch('http://localhost:8000/v1/run/', {
110
+ method: 'POST',
111
+ headers: {
112
+ 'Content-Type': 'application/json'
113
+ },
114
+ body: JSON.stringify({
115
+ code: "print('hello, world!')"
116
+ })
117
+ })
118
+ .then(response => response.json())
119
+ .then(data => console.log(data))
120
+ .catch(error => console.error('Error:', error));
121
+ ```
122
+
123
+ Or if you prefer the terminal.
124
+
125
+ `curl -X POST http://localhost:8000/v1/run/ -H "Content-Type: application/json" -d '{"code": "print(\'hello, world!\')"}'`
126
+
127
+ ### pip install
128
+
129
+ Install AgentRun with a single command via pip (you will need to configure your own Docker setup):
130
+
131
+ ```bash
132
+ pip install agentrun
133
+ ```
134
+
135
+ Here is a simple example:
136
+
137
+ ```Python
138
+ from agentrun import AgentRun
139
+
140
+ runner = AgentRun(container_name="my_container") # container should be running
141
+ code_from_llm = get_code_from_llm(prompt) # "print('hello, world!')"
142
+
143
+ result = runner.execute_code_in_container(code_from_llm)
144
+ print(result)
145
+ #> "Hello, world!"
146
+ ```
147
+
148
+
149
+
150
+ Difference | Python Package | REST API |
151
+ --------- | -------------- | ----------- |
152
+ Docker setup| You set it up | Already setup for you |
153
+ Installation| Pip | Git clone |
154
+ Ease of use | Easy | Super Easy |
155
+ Requirements| A running docker container| Docker installed |
156
+ Customize | Fully | Partially |
157
+
158
+
159
+
160
+ ## Usage
161
+
162
+ Now, let's see AgentRun in action with something more complicated. We will take advantage of function calling and AgentRun, to have LLMs write and execute code on the fly to solve arbitrary tasks. You can find the full code under `docs/examples/`
163
+
164
+ First, we will install the needed packages. We are using mixtral here via groq to keep things fast and with minimal depenencies, but AgentRun works with any LLM out of the box. All what's required is for the LLM to return a code snippet.
165
+
166
+ > FYI: OpenAI assistant tool `code_interpreter` can execute code. AgentRun is a transparent, open-source version that can work with any LLM.
167
+
168
+ ```bash
169
+ !pip install groq
170
+ !pip install requests
171
+ ```
172
+
173
+ Next, we will setup a function that executed the code and returns an output. We are using the API here, so make sure to have it running before trying this.
174
+
175
+ Here is the steps to run the API:
176
+ ```bash
177
+ git clone https://github.com/Jonathan-Adly/agentrun
178
+ cd agentrun/agentrun-api
179
+ cp .env.example .env.dev
180
+ docker-compose up -d --build
181
+ ```
182
+
183
+ ```python
184
+ def execute_python_code(code: str) -> str:
185
+ response = requests.post("http://localhost:8000/v1/run/", json={"code": code})
186
+ output = response.json()["output"]
187
+ return output
188
+ ```
189
+
190
+ Next, we will setup our LLM function calling skeleton code. We need:
191
+
192
+ 1. An LLM client such Groq or OpenAI or Anthropic (alternatively, you can use litellm as wrapper)
193
+ 2. The model you will use
194
+ 3. Our code execution tool - that encourages the LLM model to send us python code to execute reliably
195
+
196
+ ```python
197
+ from groq import Groq
198
+ import json
199
+
200
+ client = Groq(api_key ="Your API Key")
201
+
202
+ MODEL = 'mixtral-8x7b-32768'
203
+
204
+ tools = [
205
+ {
206
+ "type": "function",
207
+ "function": {
208
+ "name": "execute_python_code",
209
+ "description": "Sends a python code snippet to the code execution environment and returns the output. The code execution environment can automatically import any library or package by importing.",
210
+ "parameters": {
211
+ "type": "object",
212
+ "properties": {
213
+ "code": {
214
+ "type": "string",
215
+ "description": "The code snippet to execute. Must be a valid python code. Must use print() to output the result.",
216
+ },
217
+ },
218
+ "required": ["code"],
219
+ },
220
+ },
221
+ },
222
+ ]
223
+ ```
224
+
225
+ Next, we will setup a function to call our LLM of choice.
226
+ ```python
227
+ def chat_completion_request(messages, tools=None, tool_choice=None, model=GPT_MODEL):
228
+ try:
229
+ response = client.chat.completions.create(
230
+ model=model,
231
+ messages=messages,
232
+ tools=tools,
233
+ tool_choice=tool_choice,
234
+ )
235
+ return response
236
+ except Exception as e:
237
+ print("Unable to generate ChatCompletion response")
238
+ print(f"Exception: {e}")
239
+ return e
240
+ ```
241
+
242
+ Finally, we will set up a function that takes the user query and returns an answer. Using AgentRun to execute code when the LLM determines code execution is necesary to answer the question
243
+
244
+ ```python
245
+ def get_answer(query):
246
+ messages = []
247
+ messages.append(
248
+ {
249
+ "role": "system",
250
+ "content": """Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\n
251
+ Use the execute_python_code tool to run code if a question is better solved with code. You can use any package in the code snippet by simply importing. Like `import requests` would work fine.\n
252
+ """,
253
+ }
254
+ )
255
+ messages.append({"role": "user", "content": query})
256
+
257
+ chat_response = chat_completion_request(messages, tools=tools)
258
+
259
+ message = chat_response.choices[0].message
260
+ # tool call versus content
261
+ if message.tool_calls:
262
+ tool_call = message.tool_calls[0]
263
+ arg = json.loads(tool_call.function.arguments)["code"]
264
+ print(f"Executing code: {arg}")
265
+ answer = execute_python_code(arg)
266
+ # Optional: call an LLM again to turn the answer to a human friendly response
267
+ query = "Help translate the code output to a human friendly response. This was the user query: " + query + " The code output is: " + answer
268
+ answer = get_answer(query)
269
+ else:
270
+ answer = message.content
271
+
272
+ return answer
273
+ ```
274
+
275
+ Now let's try it!
276
+ `get_answer("what's the average daily move of Apple stock in the last 3 days?")`
277
+ "The average daily movement of Apple's stock in the last 3 days is approximately $2.60."
278
+
279
+
280
+ **How did get this answer?**
281
+
282
+ First, the LLM generated the code to call the Yahoo stock API (via yf) as such:
283
+
284
+ ```Python
285
+ #AI generated
286
+ import yfinance as yf
287
+
288
+ # Setting the ticker and period for the last 3 days
289
+ apple = yf.Ticker('AAPL')
290
+ hist = apple.history(period="3d")
291
+
292
+ # Calculating daily moves (close - open) and their average
293
+ moves = hist['Close'] - hist['Open']
294
+ average_move = moves.mean()
295
+
296
+ print(f'{average_move:.2f}')
297
+ ```
298
+
299
+ That code was sent to AgentRun, which outputted:
300
+ `'\r[*********************100%%**********************] 1 of 1 completed\n2.39'`
301
+
302
+ Lastly, the output was sent to the LLM again to make human friendly. Giving us the final answer: $2.39
303
+
304
+
305
+
306
+ ## Customize
307
+
308
+ AgentRun has sane defaults, but totally customizable. You can change:
309
+
310
+ 1. dependencies_whitelist - by default any thing that can be pip installed is allowable.
311
+ 2. cached_dependencies - these are dependencies that are installed on the image on initialization, and stay there until the image is brought down. `[]` by default.
312
+
313
+ > It will take longer to initialize the image with cached_dependencies, however subsequent runs using those dependencies would be a lot faster.
314
+
315
+ 3. cpu_quota - the default is 50000. Here is GPT-4 explaining what does that mean.
316
+
317
+ > In Docker SDK, the cpu_quota parameter is used to limit CPU usage for a container.
318
+ > The value of cpu_quota specifies the amount of CPU time that the container is allowed to use in microseconds per scheduling period.
319
+ > The default scheduling period for Docker is 100 milliseconds (100,000 microseconds).
320
+ >
321
+ > If you set cpu_quota to 50000, this means that the container is allowed to use 50,000 microseconds of CPU time every 100 milliseconds.
322
+ > Essentially, this limits the container to 50% CPU usage of a single CPU core during each scheduling period.
323
+ > If your system has multiple cores, the container could still potentially use more total CPU resources by spreading the load across multiple cores.
324
+
325
+ 3. default_timeout - how long is scripts allowed to run for. Default is 20 seconds.
326
+ 4. memory_limit - how much memory can execution take. Default is 100mb
327
+ 5. memswap_limit - the default is 512mb. Again, here is GPT-4 explaing what memory_mit and memswap do.
328
+
329
+ > In Docker SDK, the memswap_limit parameter is used to control the memory and swap usage of a container.
330
+ > This setting specifies the maximum amount of combined memory and swap space that the container can use. The value is given in bytes.
331
+ >
332
+ > Here’s how it works:
333
+
334
+ > - Memory (RAM): This is the actual physical memory that the container can use.
335
+ > - Swap: This is a portion of the hard drive that is used when the RAM is fully utilized.
336
+ > Using swap allows the system to handle more memory allocation than the physical memory available, but accessing swap is significantly slower than accessing RAM.
337
+
338
+
339
+ You can change any of the defauts when you initalize AgentRun as below.
340
+
341
+ ```Python
342
+ from agentrun import AgentRun
343
+ # container should be running
344
+ runner = AgentRun(
345
+ container_name="my_container",
346
+ # only allowed to pip install requests
347
+ dependencies_whitelist = ["requests"], # [] = no dependencies
348
+ cached_dependencies = ["requests"],
349
+ # 3 minutes timeout
350
+ default_timeout = 3 * 60,
351
+ # how much RAM can the script use
352
+ memory_limit = "512mb"
353
+ # how much total memory the script can use, using a portion of the hard drive that is used when the RAM is fully utilize
354
+ memswap_limit= "1gb"
355
+ )
356
+ code_from_llm = get_code_from_llm(prompt) # "print('hello, world!')"
357
+
358
+ result = runner.execute_code_in_container(code_from_llm)
359
+ print(result)
360
+ #> "Hello, world!"
361
+ ```
362
+
363
+
364
+ ## Benchmarks
365
+
366
+ AgentRun Median execution time is <200ms without dependencies and ~400ms with 1 "average" dependency like requests. Dependency installing is usually the bottleneck and depends on the size of package and if the package has many dependencies as well as caching.
367
+
368
+ ![benchmarks](<https://pbs.twimg.com/media/GabL6e0XgAA9Two?format=png>)
369
+
370
+
371
+
372
+ ## Development
373
+
374
+ To contribute to this library, first checkout the code. Then create a new virtual environment:
375
+ ```bash
376
+ cd agentrun
377
+ python -m venv venv
378
+ source venv/bin/activate
379
+ ```
380
+ Now install the dependencies and test dependencies:
381
+ ```bash
382
+ pip install -e '.[test]'
383
+ ```
384
+ To run the tests:
385
+ ```bash
386
+ pytest
387
+ ```
388
+
389
+ To run the test with coverage
390
+ ```bash
391
+ pytest --cov=agentrun tests/
392
+ ```