@pydantic/logfire-agent-sandboxes 0.0.0-stage → 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +24 -2
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +33 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +1 -0
- package/package.json +67 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 - present Pydantic Services inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Logfire Agent Sandboxes
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Run Python that your AI agents write in isolated, remote [Pydantic Monty](https://pydantic.dev/docs/monty/) sandboxes
|
|
4
|
+
hosted by [Pydantic Logfire](https://pydantic.dev/logfire), from Node.js.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm install @pydantic/logfire-agent-sandboxes @pydantic/monty@^1.4.0
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Create a Logfire project API key with the **Run code in this project's agent sandboxes** permission
|
|
11
|
+
(`project:execute_agent_sandboxes`) and set it as `LOGFIRE_API_KEY`. The key also selects your data region.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { agentSandboxes } from '@pydantic/logfire-agent-sandboxes'
|
|
15
|
+
|
|
16
|
+
await using pool = await agentSandboxes()
|
|
17
|
+
await using session = await pool.checkout()
|
|
18
|
+
console.log(await session.feedRun('sum([20, 21, 1])')) // 42
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`agentSandboxes()` resolves to a `MontyWebsocket` pool from `@pydantic/monty`, set up with your API key, region URL,
|
|
22
|
+
and the trace context active at each checkout. It accepts every `MontyWebsocket` option, plus `apiKey` and `url`.
|
|
23
|
+
|
|
24
|
+
See the [Agent Sandboxes docs](https://github.com/pydantic/logfire-js/blob/main/docs/agent-sandboxes.md) for host
|
|
25
|
+
functions, sessions, snapshots, and options.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@opentelemetry/api"),t=require("@pydantic/monty"),n=require("logfire");function r(e){let t=new URL(e);return t.protocol===`https:`?t.protocol=`wss:`:t.protocol===`http:`&&(t.protocol=`ws:`),t.pathname=`${t.pathname.replace(/\/+$/u,``)}/monty-ws/`,t.toString()}async function i(i={}){let{apiKey:a,connectHeaders:o,url:s,...c}=i,l=[a,process.env.LOGFIRE_API_KEY].find(e=>e!==void 0&&e!==``);if(l===void 0)throw Error("Agent sandboxes require a Logfire API key with the `project:execute_agent_sandboxes` scope. Set the LOGFIRE_API_KEY environment variable or pass `apiKey` to `agentSandboxes()`.");let u=s??r((0,n.resolveBaseUrl)(process.env,void 0,l)),d=async()=>{let t={};return e.propagation.inject(e.context.active(),t),t.authorization=`Bearer ${l}`,o===void 0?t:{...t,...await o()}};return t.MontyWebsocket.create(u,{...c,connectHeaders:d})}exports.agentSandboxes=i;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { MontyWebsocket, MontyWebsocketOptions } from "@pydantic/monty";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
export interface AgentSandboxesOptions extends MontyWebsocketOptions {
|
|
4
|
+
/**
|
|
5
|
+
* A Logfire API key with the `project:execute_agent_sandboxes` scope.
|
|
6
|
+
* Defaults to the `LOGFIRE_API_KEY` environment variable.
|
|
7
|
+
*/
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The WebSocket URL of the sandboxes server.
|
|
11
|
+
* Defaults to the Logfire region the API key belongs to, or `LOGFIRE_BASE_URL` when set.
|
|
12
|
+
*/
|
|
13
|
+
url?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Connects to Logfire Agent Sandboxes, remote Pydantic Monty workers hosted by Logfire.
|
|
17
|
+
*
|
|
18
|
+
* Resolves to a `MontyWebsocket` pool from `@pydantic/monty`; check out sessions from it:
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* await using pool = await agentSandboxes()
|
|
22
|
+
* await using session = await pool.checkout()
|
|
23
|
+
* const result = await session.feedRun('1 + 1') // 2
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* No connection is made until a session is checked out. The current trace context is sent
|
|
27
|
+
* with each checkout, so the spans Logfire records for the session join the caller's trace.
|
|
28
|
+
*
|
|
29
|
+
* Omitted pool options use the defaults of the installed `@pydantic/monty` version.
|
|
30
|
+
* `connectHeaders` results are merged over the Logfire `Authorization` header and win on conflicts.
|
|
31
|
+
*/
|
|
32
|
+
export declare function agentSandboxes(options?: AgentSandboxesOptions): Promise<MontyWebsocket>;
|
|
33
|
+
//#endregion
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { MontyWebsocket, MontyWebsocketOptions } from "@pydantic/monty";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
export interface AgentSandboxesOptions extends MontyWebsocketOptions {
|
|
4
|
+
/**
|
|
5
|
+
* A Logfire API key with the `project:execute_agent_sandboxes` scope.
|
|
6
|
+
* Defaults to the `LOGFIRE_API_KEY` environment variable.
|
|
7
|
+
*/
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The WebSocket URL of the sandboxes server.
|
|
11
|
+
* Defaults to the Logfire region the API key belongs to, or `LOGFIRE_BASE_URL` when set.
|
|
12
|
+
*/
|
|
13
|
+
url?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Connects to Logfire Agent Sandboxes, remote Pydantic Monty workers hosted by Logfire.
|
|
17
|
+
*
|
|
18
|
+
* Resolves to a `MontyWebsocket` pool from `@pydantic/monty`; check out sessions from it:
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* await using pool = await agentSandboxes()
|
|
22
|
+
* await using session = await pool.checkout()
|
|
23
|
+
* const result = await session.feedRun('1 + 1') // 2
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* No connection is made until a session is checked out. The current trace context is sent
|
|
27
|
+
* with each checkout, so the spans Logfire records for the session join the caller's trace.
|
|
28
|
+
*
|
|
29
|
+
* Omitted pool options use the defaults of the installed `@pydantic/monty` version.
|
|
30
|
+
* `connectHeaders` results are merged over the Logfire `Authorization` header and win on conflicts.
|
|
31
|
+
*/
|
|
32
|
+
export declare function agentSandboxes(options?: AgentSandboxesOptions): Promise<MontyWebsocket>;
|
|
33
|
+
//#endregion
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{context as e,propagation as t}from"@opentelemetry/api";import{MontyWebsocket as n}from"@pydantic/monty";import{resolveBaseUrl as r}from"logfire";function i(e){let t=new URL(e);return t.protocol===`https:`?t.protocol=`wss:`:t.protocol===`http:`&&(t.protocol=`ws:`),t.pathname=`${t.pathname.replace(/\/+$/u,``)}/monty-ws/`,t.toString()}async function a(a={}){let{apiKey:o,connectHeaders:s,url:c,...l}=a,u=[o,process.env.LOGFIRE_API_KEY].find(e=>e!==void 0&&e!==``);if(u===void 0)throw Error("Agent sandboxes require a Logfire API key with the `project:execute_agent_sandboxes` scope. Set the LOGFIRE_API_KEY environment variable or pass `apiKey` to `agentSandboxes()`.");let d=c??i(r(process.env,void 0,u)),f=async()=>{let n={};return t.inject(e.active(),n),n.authorization=`Bearer ${u}`,s===void 0?n:{...n,...await s()}};return n.create(d,{...l,connectHeaders:f})}export{a as agentSandboxes};
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pydantic/logfire-agent-sandboxes",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
3
|
+
"description": "Run untrusted agent code in Logfire Agent Sandboxes - https://pydantic.dev/logfire",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "The Pydantic Team",
|
|
6
|
+
"email": "engineering@pydantic.dev",
|
|
7
|
+
"url": "https://pydantic.dev"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"url": "https://github.com/pydantic/logfire-js",
|
|
11
|
+
"directory": "packages/logfire-agent-sandboxes"
|
|
12
|
+
},
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"homepage": "https://pydantic.dev/logfire",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"logfire",
|
|
21
|
+
"monty",
|
|
22
|
+
"sandbox",
|
|
23
|
+
"agents",
|
|
24
|
+
"python"
|
|
25
|
+
],
|
|
26
|
+
"version": "0.1.0",
|
|
27
|
+
"type": "module",
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/index.d.cts",
|
|
39
|
+
"default": "./dist/index.cjs"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"logfire": "0.25.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@opentelemetry/api": ">=1.9.1 <1.10.0",
|
|
48
|
+
"@pydantic/monty": "^1.4.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@opentelemetry/api": ">=1.9.1 <1.10.0",
|
|
52
|
+
"@opentelemetry/context-async-hooks": "^2.8.0",
|
|
53
|
+
"@opentelemetry/core": "^2.8.0",
|
|
54
|
+
"@pydantic/monty": "^1.4.0",
|
|
55
|
+
"@types/node": "^22.5.1",
|
|
56
|
+
"vitest": "5.0.1"
|
|
57
|
+
},
|
|
58
|
+
"files": [
|
|
59
|
+
"dist",
|
|
60
|
+
"LICENSE"
|
|
61
|
+
],
|
|
62
|
+
"scripts": {
|
|
63
|
+
"dev": "vp pack --watch",
|
|
64
|
+
"build": "vp pack",
|
|
65
|
+
"lint": "vp lint",
|
|
66
|
+
"preview": "vp preview",
|
|
67
|
+
"typecheck": "tsc",
|
|
68
|
+
"test": "vp test"
|
|
69
|
+
}
|
|
6
70
|
}
|