@opencoredev/sandbox-sdk 1.0.0-beta.0 → 1.0.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.
Files changed (139) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +70 -63
  3. package/dist/ai.js +1 -1
  4. package/dist/chunk-23tjmd39.js +8 -0
  5. package/dist/chunk-2ts3evzh.js +2 -0
  6. package/dist/chunk-83avbjns.js +2 -0
  7. package/dist/chunk-8786zrns.js +2 -0
  8. package/dist/chunk-8wq767xb.js +17 -0
  9. package/dist/chunk-9w9rddra.js +2 -0
  10. package/dist/chunk-bd481sb7.js +2 -0
  11. package/dist/chunk-ckym4cht.js +23 -0
  12. package/dist/chunk-gw3n7sx7.js +5 -0
  13. package/dist/chunk-hgrwyjrb.js +2 -0
  14. package/dist/chunk-hzbssbep.js +31 -0
  15. package/dist/chunk-k60b4r27.js +2 -0
  16. package/dist/chunk-kk1hw8wa.js +1 -0
  17. package/dist/chunk-nw845a93.js +27 -0
  18. package/dist/chunk-q5vqajhg.js +2 -0
  19. package/dist/chunk-vy1j4r8f.js +2 -0
  20. package/dist/chunk-x681p5d2.js +68 -0
  21. package/dist/chunk-xgxfy2n8.js +4 -0
  22. package/dist/core/process-records.d.ts +25 -0
  23. package/dist/errors.d.ts +67 -1
  24. package/dist/files.d.ts +11 -4
  25. package/dist/git.d.ts +1 -1
  26. package/dist/http.d.ts +225 -0
  27. package/dist/index.d.ts +3 -1
  28. package/dist/index.js +1 -1
  29. package/dist/keys.d.ts +5 -0
  30. package/dist/mastra.d.ts +1 -1
  31. package/dist/mastra.js +1 -1
  32. package/dist/memory.d.ts +4 -1
  33. package/dist/memory.js +11 -9
  34. package/dist/native.d.ts +127 -0
  35. package/dist/openai.js +1 -1
  36. package/dist/peer.d.ts +9 -0
  37. package/dist/provider.d.ts +38 -5
  38. package/dist/provider.js +1 -0
  39. package/dist/providers/agentos/errors.d.ts +3 -2
  40. package/dist/providers/agentos/index.d.ts +2 -9
  41. package/dist/providers/agentos/index.js +2 -2
  42. package/dist/providers/agentos/provider.d.ts +50 -0
  43. package/dist/providers/boat/index.d.ts +52 -9
  44. package/dist/providers/boat/index.js +1 -1
  45. package/dist/providers/boat-api/exec.d.ts +15 -2
  46. package/dist/providers/boat-api/follow.d.ts +24 -0
  47. package/dist/providers/boat-api/index.d.ts +45 -7
  48. package/dist/providers/boat-api/transport.d.ts +77 -0
  49. package/dist/providers/boxd/errors.d.ts +2 -2
  50. package/dist/providers/boxd/execute.d.ts +2 -2
  51. package/dist/providers/boxd/index.d.ts +2 -22
  52. package/dist/providers/boxd/index.js +24 -4
  53. package/dist/providers/boxd/provider.d.ts +74 -0
  54. package/dist/providers/boxd/transfers.d.ts +9 -0
  55. package/dist/providers/daytona/api.d.ts +124 -0
  56. package/dist/providers/daytona/buffered.d.ts +2 -2
  57. package/dist/providers/daytona/errors.d.ts +18 -2
  58. package/dist/providers/daytona/exec.d.ts +3 -3
  59. package/dist/providers/daytona/index.d.ts +53 -4
  60. package/dist/providers/daytona/index.js +18 -10
  61. package/dist/providers/daytona/multipart.d.ts +25 -0
  62. package/dist/providers/e2b/envd.d.ts +113 -0
  63. package/dist/providers/e2b/errors.d.ts +20 -3
  64. package/dist/providers/e2b/index.d.ts +41 -3
  65. package/dist/providers/e2b/index.js +1 -1
  66. package/dist/providers/freestyle/client.d.ts +87 -0
  67. package/dist/providers/freestyle/deadline.d.ts +3 -2
  68. package/dist/providers/freestyle/errors.d.ts +14 -1
  69. package/dist/providers/freestyle/execute.d.ts +3 -7
  70. package/dist/providers/freestyle/index.d.ts +28 -2
  71. package/dist/providers/freestyle/index.js +5 -33
  72. package/dist/providers/local/docker.d.ts +10 -6
  73. package/dist/providers/local/index.d.ts +29 -0
  74. package/dist/providers/local/index.js +2 -2
  75. package/dist/providers/railway/errors.d.ts +7 -1
  76. package/dist/providers/railway/index.d.ts +2 -23
  77. package/dist/providers/railway/index.js +1 -1
  78. package/dist/providers/railway/provider.d.ts +53 -0
  79. package/dist/providers/sandboxer/index.d.ts +15 -8
  80. package/dist/providers/sandboxer/index.js +1 -1
  81. package/dist/providers/superserve/errors.d.ts +2 -2
  82. package/dist/providers/superserve/execute.d.ts +3 -8
  83. package/dist/providers/superserve/index.d.ts +32 -3
  84. package/dist/providers/superserve/index.js +5 -37
  85. package/dist/providers/superserve/routes.d.ts +80 -0
  86. package/dist/providers/superserve/session.d.ts +33 -0
  87. package/dist/providers/tenki/deadline.d.ts +1 -1
  88. package/dist/providers/tenki/errors.d.ts +3 -3
  89. package/dist/providers/tenki/exec.d.ts +1 -1
  90. package/dist/providers/tenki/files.d.ts +1 -1
  91. package/dist/providers/tenki/index.d.ts +2 -27
  92. package/dist/providers/tenki/index.js +19 -16
  93. package/dist/providers/tenki/provider.d.ts +95 -0
  94. package/dist/providers/tenki/ready.d.ts +1 -1
  95. package/dist/providers/tenki/records.d.ts +16 -0
  96. package/dist/providers/tenki/stream.d.ts +2 -2
  97. package/dist/providers/upstash/buffered.d.ts +1 -1
  98. package/dist/providers/upstash/errors.d.ts +1 -1
  99. package/dist/providers/upstash/exec.d.ts +2 -2
  100. package/dist/providers/upstash/files.d.ts +1 -1
  101. package/dist/providers/upstash/index.d.ts +2 -34
  102. package/dist/providers/upstash/index.js +12 -18
  103. package/dist/providers/upstash/provider.d.ts +81 -0
  104. package/dist/providers/vercel/errors.d.ts +3 -1
  105. package/dist/providers/vercel/index.d.ts +13 -5
  106. package/dist/providers/vercel/index.js +1 -1
  107. package/dist/providers/vercel/provider.d.ts +50 -2
  108. package/dist/providers/vercel/transport.d.ts +7 -4
  109. package/dist/run.d.ts +6 -4
  110. package/dist/shared/deadline.d.ts +12 -0
  111. package/dist/shared/guest.d.ts +18 -0
  112. package/dist/shared/json.d.ts +11 -0
  113. package/dist/shared/metadata.d.ts +19 -0
  114. package/dist/shared/narrow.d.ts +8 -0
  115. package/dist/shared/native-error.d.ts +42 -0
  116. package/dist/shared/paged-exec.d.ts +22 -0
  117. package/dist/shared/shell.d.ts +2 -0
  118. package/dist/{providers/freestyle → shared}/wire.d.ts +1 -1
  119. package/dist/shell/process-records.d.ts +44 -0
  120. package/dist/streams.d.ts +72 -0
  121. package/dist/testing.d.ts +12 -2
  122. package/dist/testing.js +7 -4
  123. package/dist/tool-security.d.ts +4 -4
  124. package/dist/tools.d.ts +3 -2
  125. package/dist/tools.js +1 -1
  126. package/dist/types.d.ts +14 -6
  127. package/package.json +29 -46
  128. package/dist/chunk-59t3rqja.js +0 -2
  129. package/dist/chunk-cwx6cc31.js +0 -2
  130. package/dist/chunk-exv1kf89.js +0 -60
  131. package/dist/chunk-gc8zdxyb.js +0 -2
  132. package/dist/chunk-hjzhc3qg.js +0 -40
  133. package/dist/chunk-md6fmprc.js +0 -1
  134. package/dist/chunk-t5vr9nd8.js +0 -8
  135. package/dist/chunk-v6y7eqxw.js +0 -27
  136. package/dist/chunk-yed8mvs7.js +0 -2
  137. package/dist/chunk-yrsb6hws.js +0 -5
  138. package/dist/chunk-z9rjzn28.js +0 -2
  139. package/dist/providers/boxd/guest.d.ts +0 -14
package/dist/keys.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import type { Provider } from "./provider.js";
2
+ import type { CreateOptions } from "./types.js";
2
3
  export declare const knownKey: (provider: Provider, key: string) => string | undefined;
3
4
  export declare function rememberKey(provider: Provider, key: string, id: string): void;
4
5
  export declare function forgetKey(provider: Provider, key: string): void;
5
6
  export declare function forgetSandbox(provider: Provider, id: string): void;
7
+ export declare function withKeyLock<T>(provider: Provider, key: string, options: Pick<CreateOptions, "keyMode" | "locator">, action: () => Promise<T>): Promise<T>;
8
+ export declare function attachHandle(provider: Provider, id: string): void;
9
+ /** Drop one handle's claim. Returns whether it was the last open handle for the sandbox. */
10
+ export declare function detachHandle(provider: Provider, id: string): boolean;
package/dist/mastra.d.ts CHANGED
@@ -39,5 +39,5 @@ export declare function sandboxTools(box: Sandbox, options?: SandboxToolsOptions
39
39
  path?: string | undefined;
40
40
  }, {
41
41
  text: string;
42
- }, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "run" | "read_file" | "write_file" | "edit_file" | "start_process" | "process_logs" | "stop_process" | "search" | "list_files" | "changes" | "preview", unknown>;
42
+ }, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "search" | "changes" | "run" | "read_file" | "write_file" | "edit_file" | "start_process" | "process_logs" | "stop_process" | "list_files" | "preview", unknown>;
43
43
  };
package/dist/mastra.js CHANGED
@@ -1 +1 @@
1
- import"./chunk-t5vr9nd8.js";import{w}from"./chunk-v6y7eqxw.js";import"./chunk-cwx6cc31.js";import{createTool as s}from"@mastra/core/tools";import{z as e}from"zod";function c(p,r){return Object.fromEntries(w(p,r).map((o)=>[o.name,s({id:o.name,description:o.description,inputSchema:o.inputSchema,outputSchema:e.object({text:e.string()}),execute:(t,a)=>o.execute(t,void 0,a?.abortSignal),toModelOutput:(t)=>({type:"text",value:t.text})})]))}export{c as sandboxTools};
1
+ import"./chunk-23tjmd39.js";import{M}from"./chunk-nw845a93.js";import"./chunk-ckym4cht.js";import{createTool as s}from"@mastra/core/tools";import{z as e}from"zod";function c(p,r){return Object.fromEntries(M(p,r).map((o)=>[o.name,s({id:o.name,description:o.description,inputSchema:o.inputSchema,outputSchema:e.object({text:e.string()}),execute:(t,a)=>o.execute(t,void 0,a?.abortSignal),toModelOutput:(t)=>({type:"text",value:t.text})})]))}export{c as sandboxTools};
package/dist/memory.d.ts CHANGED
@@ -14,9 +14,11 @@ export interface CommandContext {
14
14
  };
15
15
  }
16
16
  export type CommandHandler = (context: CommandContext) => number | Promise<number>;
17
+ /** `mode` holds POSIX permission bits; `stat -c %a` and `chmod` read and set them. */
17
18
  interface Node {
18
19
  data: Uint8Array | null;
19
20
  modifiedAt: number;
21
+ mode: number;
20
22
  }
21
23
  export interface MemoryOptions {
22
24
  handlers?: Record<string, CommandHandler>;
@@ -24,7 +26,8 @@ export interface MemoryOptions {
24
26
  export interface MemoryNative {
25
27
  readonly files: Map<string, Node>;
26
28
  }
27
- /** Offline fake. No git, shell programs outside the handler table, PTYs, or real
29
+ /** Offline fake. No git, shell programs outside the handler table (plus `cd`, `export`,
30
+ * `kill`, `chmod MODE PATH...` and `stat -c %a PATH...`), PTYs, or real
28
31
  * sockets. Preview URLs use memory.invalid and must never be fetched. Register
29
32
  * handlers with memory({handlers}) or provider.register(name, handler).
30
33
  */
package/dist/memory.js CHANGED
@@ -1,11 +1,13 @@
1
- import{b}from"./chunk-t5vr9nd8.js";import{e}from"./chunk-gc8zdxyb.js";import{posix as m}from"node:path";function Y(Z={}){let w=new Map,y=new Map,h=(r,t)=>new e(`${r}. Memory resource does not exist or request is invalid. Check the path or ID.`,{code:t,provider:"memory"}),v=(r)=>{let t=w.get(r);if(!t)throw h(`Sandbox ${r} not found`,"not_found");if(t.idleTimeoutMs)clearTimeout(t.idleTimer),t.idleTimer=setTimeout(()=>{if(t.active.size)v(r);else E.destroy(r)},t.idleTimeoutMs),t.idleTimer.unref?.();return t},M=(r,t)=>{let n=v(r).nodes.get(m.resolve("/",t));if(!n)throw h(`File ${t} not found`,"file_not_found");return n},R=()=>Date.now();function A(r,t){let n=v(r);for(let o=m.resolve("/",t);;o=m.dirname(o)){let i=n.nodes.get(o);if(i?.data)throw h(`${o} is not a directory`,"invalid_argument");if(!i)n.nodes.set(o,{data:null,modifiedAt:R()});if(o==="/")break}}let T={writeCreatesParents:!0,async readRange(r,t,n){let o=M(r,t);if(o.data===null)throw h(`${t} is a directory`,"invalid_argument");return o.data.slice(n.offset,n.offset+n.length)},async read(r,t){let n=M(r,t);if(n.data===null)throw h(`${t} is a directory`,"invalid_argument");return n.data.slice()},async write(r,t,n){let o=v(r);A(r,m.dirname(t)),o.nodes.set(m.resolve("/",t),{data:n.slice(),modifiedAt:Math.max(R(),(o.nodes.get(t)?.modifiedAt??0)+1)})},async stat(r,t){let n=M(r,t);return{path:m.resolve("/",t),type:n.data===null?"directory":"file",size:n.data?.length??0,modifiedAt:n.modifiedAt}},async list(r,t){let n=m.resolve("/",t);if(M(r,t).data!==null)throw h(`${t} is not a directory`,"invalid_argument");let o=[];for(let i of v(r).nodes.keys())if(i!==n&&m.dirname(i)===n)o.push(await T.stat(r,i));return o.sort((i,s)=>i.path.localeCompare(s.path))},async remove(r,t,n){let o=v(r),i=m.resolve("/",t);M(r,i);let s=[...o.nodes.keys()].filter((p)=>p.startsWith(i+"/"));if(s.length&&!n.recursive)throw h(`${t} is not empty`,"invalid_argument");for(let p of s)o.nodes.delete(p);o.nodes.delete(i)},async mkdir(r,t){A(r,t)}},q=({args:r,signal:t})=>new Promise((n)=>{if(t.aborted){n(137);return}let o=setTimeout(()=>{t.removeEventListener("abort",i),n(0)},Math.max(0,Number(r[0]??0)*1000)),i=()=>{clearTimeout(o),n(137)};t.addEventListener("abort",i,{once:!0})});y.set("echo",({args:r,stdout:t})=>{let n=r[0]==="-n";return t((n?r.slice(1):r).join(" ")+(n?"":`
2
- `)),0}),y.set("printf",({args:r,stdout:t})=>{let n=1;return t((r[0]??"").replace(/\\n/g,`
3
- `).replace(/\\t/g,"\t").replace(/%[sd%]/g,(o)=>o==="%%"?"%":r[n++]??"")),0}),y.set("pwd",({cwd:r,stdout:t})=>(t(r+`
4
- `),0)),y.set("true",()=>0),y.set("false",()=>1),y.set("exit",({args:r})=>Number(r[0]??0)),y.set("sleep",q),y.set("cat",async({args:r,stdin:t,stdout:n,stderr:o,files:i})=>{if(!r.length)n(t);else for(let s of r)try{n(new TextDecoder().decode(await i.read(s)))}catch{return o(`cat: ${s}: No such file or directory
5
- `),1}return 0}),y.set("ls",async({args:r,stdout:t,files:n})=>(t((await n.list(r.find((o)=>!o.startsWith("-"))??".")).map((o)=>m.basename(o.path)).join(`
1
+ import{e}from"./chunk-xgxfy2n8.js";import{posix as u}from"node:path";function V(L={}){let b=new Map,g=new Map,w=(r,t)=>new e(`${r}. Memory resource does not exist or request is invalid. Check the path or ID.`,{code:t,provider:"memory"}),v=(r)=>{let t=b.get(r);if(!t)throw w(`Sandbox ${r} not found`,"not_found");if(t.idleTimeoutMs)clearTimeout(t.idleTimer),t.idleTimer=setTimeout(()=>{if(t.active.size)v(r);else S.destroy(r)},t.idleTimeoutMs),t.idleTimer.unref?.();return t},M=(r,t)=>{let n=v(r).nodes.get(u.resolve("/",t));if(!n)throw w(`File ${t} not found`,"file_not_found");return n},I=()=>Date.now();function P(r,t){let n=v(r);for(let o=u.resolve("/",t);;o=u.dirname(o)){let s=n.nodes.get(o);if(s?.data)throw w(`${o} is not a directory`,"invalid_argument");if(!s)n.nodes.set(o,{data:null,modifiedAt:I(),mode:493});if(o==="/")break}}let C={transfer:"files",checkpoints:"files",writeCreatesParents:!0,writeSupportsMode:!0,async readRange(r,t,n){let o=M(r,t);if(o.data===null)throw w(`${t} is a directory`,"invalid_argument");return o.data.slice(n.offset,n.offset+n.length)},async read(r,t){let n=M(r,t);if(n.data===null)throw w(`${t} is a directory`,"invalid_argument");return n.data.slice()},async write(r,t,n,o){let s=v(r);P(r,u.dirname(t));let i=u.resolve("/",t),m=s.nodes.get(i);s.nodes.set(i,{data:n.slice(),modifiedAt:Math.max(I(),(m?.modifiedAt??0)+1),mode:o?.mode??m?.mode??420})},async stat(r,t){let n=M(r,t);return{path:u.resolve("/",t),type:n.data===null?"directory":"file",size:n.data?.length??0,modifiedAt:n.modifiedAt}},async list(r,t){let n=u.resolve("/",t);if(M(r,t).data!==null)throw w(`${t} is not a directory`,"invalid_argument");let o=[];for(let s of v(r).nodes.keys())if(s!==n&&u.dirname(s)===n)o.push(await C.stat(r,s));return o.sort((s,i)=>s.path.localeCompare(i.path))},async remove(r,t,n){let o=v(r),s=u.resolve("/",t);M(r,s);let i=[...o.nodes.keys()].filter((m)=>m.startsWith(s+"/"));if(i.length&&!n.recursive)throw w(`${t} is not empty`,"invalid_argument");for(let m of i)o.nodes.delete(m);o.nodes.delete(s)},async mkdir(r,t){P(r,t)}},Z=({args:r,signal:t})=>new Promise((n)=>{if(t.aborted){n(137);return}let o=setTimeout(()=>{t.removeEventListener("abort",s),n(0)},Math.max(0,Number(r[0]??0)*1000)),s=()=>{clearTimeout(o),n(137)};t.addEventListener("abort",s,{once:!0})});g.set("echo",({args:r,stdout:t})=>{let n=r[0]==="-n";return t((n?r.slice(1):r).join(" ")+(n?"":`
2
+ `)),0}),g.set("printf",({args:r,stdout:t})=>{let n=1;return t((r[0]??"").replace(/\\n/g,`
3
+ `).replace(/\\t/g,"\t").replace(/%[sd%]/g,(o)=>o==="%%"?"%":r[n++]??"")),0}),g.set("pwd",({cwd:r,stdout:t})=>(t(r+`
4
+ `),0)),g.set("true",()=>0),g.set("false",()=>1),g.set("exit",({args:r})=>Number(r[0]??0)),g.set("sleep",Z),g.set("cat",async({args:r,stdin:t,stdout:n,stderr:o,files:s})=>{if(!r.length)n(t);else for(let i of r)try{n(new TextDecoder().decode(await s.read(i)))}catch{return o(`cat: ${i}: No such file or directory
5
+ `),1}return 0}),g.set("ls",async({args:r,stdout:t,files:n})=>(t((await n.list(r.find((o)=>!o.startsWith("-"))??".")).map((o)=>u.basename(o.path)).join(`
6
6
  `)+`
7
- `),0)),y.set("printenv",({args:r,env:t,stdout:n})=>(n((r.length?r.map((o)=>t[o]??""):Object.entries(t).map(([o,i])=>`${o}=${i}`)).join(`
7
+ `),0)),g.set("printenv",({args:r,env:t,stdout:n})=>(n((r.length?r.map((o)=>t[o]??""):Object.entries(t).map(([o,s])=>`${o}=${s}`)).join(`
8
8
  `)+`
9
- `),0));for(let[r,t]of Object.entries(Z.handlers??{}))y.set(r,t);function W(r,t){let n=[],o="",i=!1,s="plain",p=()=>{if(i)n.push({text:o,operator:!1});o="",i=!1};for(let d=0;d<r.length;d++){let c=r[d]??"";if(s==="single"){if(c==="'")s="plain";else o+=c;continue}if(c==="'"&&s==="plain"){s="single",i=!0;continue}if(c==='"'){s=s==="double"?"plain":"double",i=!0;continue}if(c==="\\"){let u=r[++d]??"";o+=u==="n"?"\\n":u,i=!0;continue}if(c==="$"){let u=r.slice(d+1),C=/^(?:\{([A-Za-z_][A-Za-z0-9_]*)\}|([A-Za-z_][A-Za-z0-9_]*))/.exec(u);if(C){o+=t[C[1]??C[2]??""]??"",d+=C[0].length,i=!0;continue}}if(s==="plain"&&/\s/.test(c)){p();continue}if(s==="plain"&&"><".includes(c)&&i&&/^\d+$/.test(o)){let u=o;o="",i=!1,n.push({text:u+c,operator:!0});continue}if(s==="plain"&&c===">"&&r.slice(d,d+3)===">&2"){p(),n.push({text:">&2",operator:!0}),d+=2;continue}if(s==="plain"&&";&>|<".includes(c)){p();let u=c;if(r[d+1]===c)u+=r[++d];n.push({text:u,operator:!0});continue}o+=c,i=!0}if(s!=="plain")throw h("Unclosed shell quote","invalid_argument");return p(),n}async function z(r,t){let n=v(r),o=new AbortController;n.active.add(o);let i=!1,s=()=>{i=!0,o.abort()};if(t.signal?.addEventListener("abort",s,{once:!0}),t.signal?.aborted)s();let p=setTimeout(s,t.timeoutMs),d=t.cwd,c={...n.env,...t.env},u=0,C=!1;try{if(t.activityPath)A(r,m.dirname(t.activityPath)),await T.write(r,t.activityPath,new Uint8Array([1]));if(t.command===b){let l=n.nodes.get("/tmp/.sandbox-sdk/secret-names.json");if(l?.data)t.onChunk({stream:"stdout",text:new TextDecoder().decode(l.data)+"\x00"+Object.entries(c).map(([f,_])=>`${f}=${_}\x00`).join("")});return{exitCode:0,timedOut:!1}}let g=W(t.command,c),G=g.find((l)=>l.operator&&![";","&&","||",">",">&2"].includes(l.text)),K=g.find((l,f)=>l.operator&&l.text===">"&&(!g[f+1]||g[f+1]?.operator||g[f+2]&&!g[f+2]?.operator)),B=g.find((l,f)=>l.operator&&["&&","||"].includes(l.text)&&(!g[f-1]||[";","&&","||"].includes(g[f-1]?.text??"")||!g[f+1]||g[f+1]?.operator)),j=0,J=g.find((l)=>{if(!l.operator)return!1;if([";","&&","||"].includes(l.text))j=0;else if([">",">&2"].includes(l.text))return++j>1;return!1}),U=G??K??B??J;if(U)return t.onChunk({stream:"stderr",text:`Unsupported shell syntax: ${U.text} (memory provider)
10
- `}),{exitCode:127,timedOut:!1};let O=[],I=";";async function H(l){let f=O;O=[];let _=f.findIndex((a)=>a.operator&&a.text===">&2");if(_>=0)f.splice(_,1);let N=f.findIndex((a)=>a.operator&&a.text===">"),S=N>=0?f[N+1]?.text:void 0;if(N>=0)f.splice(N);let P=f.map((a)=>a.text);if(!P.length||C||o.signal.aborted||I==="&&"&&u!==0||I==="||"&&u===0){I=l;return}I=l;let k=P.shift()??"";if(k==="cd"){if(d=m.resolve(d,P[0]??"/workspace"),M(r,d).data!==null)throw h("Not a directory","invalid_argument");u=0;return}if(k==="export"){for(let a of P){let x=a.indexOf("=");if(x>=0)c[a.slice(0,x)]=a.slice(x+1)}return}if(k==="kill"){let a=Math.abs(Number(P.find((x)=>/^-?\d+$/.test(x))));n.processes.get(a)?.controller.abort();return}if(k==="exit")C=!0;let D=y.get(k);if(!D){t.onChunk({stream:"stderr",text:`${k}: command not found (memory handler not registered)
11
- `}),u=127;return}let F="",L=(a,x)=>{if(!o.signal.aborted)if(S&&a==="stdout")F+=x;else t.onChunk({stream:a,text:x})};if(u=await D({args:P,cwd:d,env:c,stdin:t.stdin??"",signal:o.signal,stdout:(a)=>L(_>=0?"stderr":"stdout",a),stderr:(a)=>L("stderr",a),files:{read:(a)=>T.read(r,m.resolve(d,a)),write:(a,x)=>T.write(r,m.resolve(d,a),typeof x==="string"?new TextEncoder().encode(x):x),list:(a)=>T.list(r,m.resolve(d,a))}}),S)await T.write(r,m.resolve(d,S),new TextEncoder().encode(F))}for(let l of g)if(l.operator&&[";","&&","||"].includes(l.text))await H(l.text);else O.push(l);return await H(";"),{exitCode:i?null:u,timedOut:i}}finally{if(t.activityPath){if(n.nodes.delete(t.activityPath),w.has(r))v(r)}n.active.delete(o),clearTimeout(p),t.signal?.removeEventListener("abort",s)}}let E={name:"memory",inlineActivity:!0,keyMode:"exact",capabilities:new Set(["network-policy"]),files:T,register(r,t){y.set(r,t)},async create(r){if(r.size!==void 0)throw new e("Memory cannot enforce machine size. Omit size or choose a provider with size support.",{code:"unsupported",provider:"memory"});if(r.key){if([...w.values()].find((i)=>i.info.key===r.key))throw new e("Key already exists. Another caller created it. Find the existing sandbox.",{code:"provider",provider:"memory"})}let t=`mem-${crypto.randomUUID()}`,n={id:t,key:r.key,labels:{...r.labels},state:"running",createdAt:R()};if(w.set(t,{info:n,nodes:new Map,env:{...r.env},processes:new Map,nextPid:100,active:new Set,idleTimeoutMs:r.idleTimeoutMs}),r.timeoutMs){let o=v(t);o.lifetimeTimer=setTimeout(()=>{E.destroy(t)},r.timeoutMs),o.lifetimeTimer.unref?.()}return A(t,"/workspace"),A(t,"/tmp"),n},async find(r){return[...w.values()].find((t)=>t.info.key===r)?.info},async connect(r){return v(r).info},async list(r){return[...w.values()].map((t)=>t.info).filter((t)=>Object.entries(r).every(([n,o])=>t.labels[n]===o))},async destroy(r){let t=w.get(r);if(!t)return;clearTimeout(t.idleTimer),clearTimeout(t.lifetimeTimer);for(let n of t.active)n.abort();for(let n of t.processes.values())n.controller.abort();await Promise.allSettled([...t.processes.values()].map((n)=>n.result)),w.delete(r)},exec:z,async previewUrl(r,t){return v(r),{url:`https://${r}-${t}.memory.invalid/`}},native(r){return{files:v(r).nodes}},async startProcess(r,t){let n=v(r),o=n.nextPid++,i=new AbortController,s=z(r,{...t,timeoutMs:2147483647,signal:i.signal});return n.processes.set(o,{controller:i,result:s}),s.then(()=>n.processes.delete(o),()=>n.processes.delete(o)),{pid:o,wait:async()=>{let p=await s;return{exitCode:p.timedOut?143:p.exitCode,signal:p.timedOut?"SIGTERM":null}},stop:async()=>{i.abort(),await s}}}};return E}export{Y as memory};
9
+ `),0));for(let[r,t]of Object.entries(L.handlers??{}))g.set(r,t);function q(r,t){let n=[],o="",s=!1,i="plain",m=()=>{if(s)n.push({text:o,operator:!1});o="",s=!1};for(let l=0;l<r.length;l++){let f=r[l]??"";if(i==="single"){if(f==="'")i="plain";else o+=f;continue}if(f==="'"&&i==="plain"){i="single",s=!0;continue}if(f==='"'){i=i==="double"?"plain":"double",s=!0;continue}if(f==="\\"){let d=r[++l]??"";o+=d==="n"?"\\n":d,s=!0;continue}if(f==="$"){let d=r.slice(l+1),k=/^(?:\{([A-Za-z_][A-Za-z0-9_]*)\}|([A-Za-z_][A-Za-z0-9_]*))/.exec(d);if(k){o+=t[k[1]??k[2]??""]??"",l+=k[0].length,s=!0;continue}}if(i==="plain"&&/\s/.test(f)){m();continue}if(i==="plain"&&"><".includes(f)&&s&&/^\d+$/.test(o)){let d=o;o="",s=!1,n.push({text:d+f,operator:!0});continue}if(i==="plain"&&f===">"&&r.slice(l,l+3)===">&2"){m(),n.push({text:">&2",operator:!0}),l+=2;continue}if(i==="plain"&&";&>|<".includes(f)){m();let d=f;if(r[l+1]===f)d+=r[++l];n.push({text:d,operator:!0});continue}o+=f,s=!0}if(i!=="plain")throw w("Unclosed shell quote","invalid_argument");return m(),n}async function z(r,t){let n=v(r),o=new AbortController;n.active.add(o);let s=!1,i=()=>{s=!0,o.abort()};if(t.signal?.addEventListener("abort",i,{once:!0}),t.signal?.aborted)i();let m=setTimeout(i,t.timeoutMs),l=t.cwd,f={...n.env,...t.env},d=0,k=!1;try{if(t.activityPath)P(r,u.dirname(t.activityPath)),await C.write(r,t.activityPath,new Uint8Array([1]));let h=q(t.command,f),W=h.find((c)=>c.operator&&![";","&&","||",">",">&2"].includes(c.text)),G=h.find((c,p)=>c.operator&&c.text===">"&&(!h[p+1]||h[p+1]?.operator||h[p+2]&&!h[p+2]?.operator)),K=h.find((c,p)=>c.operator&&["&&","||"].includes(c.text)&&(!h[p-1]||[";","&&","||"].includes(h[p-1]?.text??"")||!h[p+1]||h[p+1]?.operator)),O=0,B=h.find((c)=>{if(!c.operator)return!1;if([";","&&","||"].includes(c.text))O=0;else if([">",">&2"].includes(c.text))return++O>1;return!1}),U=W??G??K??B;if(U)return t.onChunk({stream:"stderr",text:`Unsupported shell syntax: ${U.text} (memory provider)
10
+ `}),{exitCode:127,timedOut:!1};let N=[],A=";";async function j(c){let p=N;N=[];let E=p.findIndex((a)=>a.operator&&a.text===">&2");if(E>=0)p.splice(E,1);let _=p.findIndex((a)=>a.operator&&a.text===">"),R=_>=0?p[_+1]?.text:void 0;if(_>=0)p.splice(_);let x=p.map((a)=>a.text);if(!x.length||k||o.signal.aborted||A==="&&"&&d!==0||A==="||"&&d===0){A=c;return}A=c;let T=x.shift()??"";if(T==="cd"){if(l=u.resolve(l,x[0]??"/workspace"),M(r,l).data!==null)throw w("Not a directory","invalid_argument");d=0;return}if(T==="export"){for(let a of x){let y=a.indexOf("=");if(y>=0)f[a.slice(0,y)]=a.slice(y+1)}return}if(T==="kill"){let a=Math.abs(Number(x.find((y)=>/^-?\d+$/.test(y))));n.processes.get(a)?.controller.abort();return}if(T==="exit")k=!0;if(T==="chmod"){let a=Number.parseInt(x[0]??"",8);if(!/^[0-7]{1,4}$/.test(x[0]??"")||x.length<2){t.onChunk({stream:"stderr",text:`chmod: only octal modes are supported (memory provider)
11
+ `}),d=1;return}for(let y of x.slice(1))M(r,u.resolve(l,y)).mode=a;d=0;return}if(T==="stat"&&x[0]==="-c"&&x[1]==="%a"){for(let a of x.slice(2))t.onChunk({stream:"stdout",text:`${M(r,u.resolve(l,a)).mode.toString(8)}
12
+ `});d=0;return}let H=g.get(T);if(!H){t.onChunk({stream:"stderr",text:`${T}: command not found (memory handler not registered)
13
+ `}),d=127;return}let D="",F=(a,y)=>{if(!o.signal.aborted)if(R&&a==="stdout")D+=y;else t.onChunk({stream:a,text:y})};if(d=await H({args:x,cwd:l,env:f,stdin:t.stdin??"",signal:o.signal,stdout:(a)=>F(E>=0?"stderr":"stdout",a),stderr:(a)=>F("stderr",a),files:{read:(a)=>C.read(r,u.resolve(l,a)),write:(a,y)=>C.write(r,u.resolve(l,a),y instanceof Uint8Array?y:new TextEncoder().encode(y)),list:(a)=>C.list(r,u.resolve(l,a))}}),R)await C.write(r,u.resolve(l,R),new TextEncoder().encode(D))}for(let c of h)if(c.operator&&[";","&&","||"].includes(c.text))await j(c.text);else N.push(c);return await j(";"),{exitCode:s?null:d,timedOut:s}}finally{if(t.activityPath){if(n.nodes.delete(t.activityPath),b.has(r))v(r)}n.active.delete(o),clearTimeout(m),t.signal?.removeEventListener("abort",i)}}let S={name:"memory",inlineActivity:!0,processMode:"stream",previewMode:"placeholder",keyMode:"exact",capabilities:new Set(["network-policy"]),files:C,register(r,t){g.set(r,t)},async create(r){if(r.size!==void 0)throw new e("Memory cannot enforce machine size. Omit size or choose a provider with size support.",{code:"unsupported",provider:"memory"});if(r.key){if([...b.values()].find((s)=>s.info.key===r.key))throw new e("Key already exists. Another caller created it. Find the existing sandbox.",{code:"provider",provider:"memory"})}let t=`mem-${crypto.randomUUID()}`,n={id:t,key:r.key,labels:{...r.labels},state:"running",createdAt:I()};if(b.set(t,{info:n,nodes:new Map,env:{...r.env},processes:new Map,nextPid:100,active:new Set,idleTimeoutMs:r.idleTimeoutMs}),r.timeoutMs){let o=v(t);o.lifetimeTimer=setTimeout(()=>{S.destroy(t)},r.timeoutMs),o.lifetimeTimer.unref?.()}return P(t,"/workspace"),P(t,"/tmp"),n},async find(r){return[...b.values()].find((t)=>t.info.key===r)?.info},async connect(r){return v(r).info},async list(r){let t=[];for(let{info:n}of b.values())if(Object.entries(r).every(([o,s])=>n.labels[o]===s))t.push(n);return t},async destroy(r){let t=b.get(r);if(!t)return;clearTimeout(t.idleTimer),clearTimeout(t.lifetimeTimer);for(let n of t.active)n.abort();for(let n of t.processes.values())n.controller.abort();await Promise.allSettled([...t.processes.values()].map((n)=>n.result)),b.delete(r)},exec:z,async readSecretEnvironment(r){let t=v(r),n=t.nodes.get("/tmp/.sandbox-sdk/secret-names.json");if(!n?.data)return;return{record:new TextDecoder().decode(n.data),environment:{...t.env}}},async previewUrl(r,t){return v(r),{url:`https://${r}-${t}.memory.invalid/`}},native(r){return{files:v(r).nodes}},async startProcess(r,t){let n=v(r),o=n.nextPid++,s=new AbortController,i=z(r,{...t,timeoutMs:2147483647,signal:s.signal});return n.processes.set(o,{controller:s,result:i}),i.then(()=>n.processes.delete(o),()=>n.processes.delete(o)),{pid:o,wait:async()=>{let m=await i;return{exitCode:m.timedOut?143:m.exitCode,signal:m.timedOut?"SIGTERM":null}},stop:async()=>{s.abort(),await i}}}};return S}export{V as memory};
@@ -0,0 +1,127 @@
1
+ import type { JsonValue } from "./shared/json.js";
2
+ import type { HttpClient } from "./http.js";
3
+ /** An HTTP method `box.native.request` and `box.native.fetch` accept. */
4
+ export type HttpMethod = "GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE";
5
+ /** Options for one raw call through {@link NativeApi}. */
6
+ export interface NativeRequestOptions<Plane extends string = string> {
7
+ /**
8
+ * Which of the provider's APIs to call, such as Daytona's `"api"` or `"toolbox"`. Each provider page lists
9
+ * its planes. Default: the provider's control plane.
10
+ */
11
+ plane?: Plane;
12
+ /**
13
+ * Values for `{name}` placeholders in the path, URI-encoded. Only the provider's own sandbox placeholder
14
+ * (such as `{sandboxId}`) fills itself on `box.native`; every other placeholder must be here, or the call
15
+ * fails with `invalid_argument` before any request. A value here wins over the automatic one.
16
+ */
17
+ params?: Record<string, string | number>;
18
+ /** Query string values. `undefined` values are left out. */
19
+ query?: Record<string, string | number | boolean | undefined>;
20
+ /**
21
+ * The request body. A `string`, `Uint8Array`, `ArrayBuffer`, `Blob`, `FormData`, `URLSearchParams` or
22
+ * `ReadableStream` is sent as it is; anything else is sent as JSON.
23
+ */
24
+ body?: unknown;
25
+ /** Extra request headers. They win over the SDK's own headers, except that credentials never leave the provider's origin. */
26
+ headers?: Record<string, string>;
27
+ /** Abort the call. It rejects with a `SandboxError` whose code is `aborted`. */
28
+ signal?: AbortSignal;
29
+ /**
30
+ * Give up after this many milliseconds. `request` counts the whole call, including the response body;
31
+ * `fetch` counts until the response headers arrive. Default: the provider's request timeout.
32
+ */
33
+ timeoutMs?: number;
34
+ }
35
+ /**
36
+ * The widest type of `sdk` on a {@link NativeApi}: it takes a function that imports the provider's official
37
+ * SDK and resolves to that SDK's object for this sandbox. Each provider narrows it with a structural
38
+ * constraint on the module, so the result type comes from the module you imported, not from this package:
39
+ *
40
+ * ```ts
41
+ * type DaytonaSdk = <M extends { Daytona: new (config: object) => { get(id: string): Promise<unknown> } }>(
42
+ * load: () => Promise<M>) => Promise<Awaited<ReturnType<InstanceType<M["Daytona"]>["get"]>>>;
43
+ * ```
44
+ *
45
+ * Every provider's `sdk` is assignable to this one, so a plain `NativeApi` accepts any provider's native API.
46
+ * Through a plain `NativeApi` the module is unknown, so `sdk` cannot be called; use the provider's own type.
47
+ */
48
+ export type NativeSdkLoader = (load: () => Promise<never>) => Promise<object>;
49
+ /** The `sdk` loader of a provider that does not describe its module: any module in, `unknown` out. */
50
+ export type AnyNativeSdk = <M extends object>(load: () => Promise<M>) => Promise<object>;
51
+ /**
52
+ * Direct access to a provider's HTTP API, with the adapter's base URLs, credentials, retries, error mapping
53
+ * and redaction. On a sandbox it is `box.native`; on a provider factory it is `provider.api`, with no
54
+ * sandbox bound.
55
+ *
56
+ * ```ts
57
+ * const box = await createSandbox(daytona());
58
+ * const files = await box.native.request<{ name: string }[]>("GET", "/files", { plane: "toolbox", query: { path: "/workspace" } });
59
+ * const sdkSandbox = await box.native.sdk(() => import("@daytonaio/sdk"));
60
+ * ```
61
+ */
62
+ export interface NativeApi<Plane extends string = string, Sdk extends NativeSdkLoader = NativeSdkLoader> {
63
+ /** The sandbox this client is bound to. `undefined` on `provider.api`. */
64
+ readonly sandboxId?: string;
65
+ /**
66
+ * Call an endpoint and return its JSON body, or `undefined` for an empty body (such as a 204). `T` is
67
+ * not checked at runtime. A non-2xx response rejects with a `SandboxError`. A `GET`, `HEAD`, `PUT` or
68
+ * `DELETE` is retried on 429, 502, 503, 504 and network errors; other methods are never retried.
69
+ */
70
+ request<T = unknown>(method: HttpMethod, path: string, options?: NativeRequestOptions<Plane>): Promise<T>;
71
+ /**
72
+ * Call an endpoint and return the raw `Response`, for bytes and streams. A non-2xx response still
73
+ * rejects with a `SandboxError`. You own the body: read it or call `response.body?.cancel()`.
74
+ */
75
+ fetch(method: HttpMethod, path: string, options?: NativeRequestOptions<Plane>): Promise<Response>;
76
+ /**
77
+ * Hand over the provider's official SDK module, imported by you, and get its object for this sandbox
78
+ * (or its client on `provider.api`): `await box.native.sdk(() => import("@daytonaio/sdk"))`. The SDK is
79
+ * not a dependency of this package; install it yourself to use this. Rejects with `unavailable` when the
80
+ * import fails and `invalid_argument` when the module does not have the expected exports.
81
+ */
82
+ readonly sdk: Sdk;
83
+ }
84
+ /** How an adapter turns the caller's SDK module into the object `sdk()` returns. */
85
+ export interface NativeSdkBinding {
86
+ /** The npm package, for messages: `"@daytonaio/sdk"`. */
87
+ readonly package: string;
88
+ /**
89
+ * Build the SDK object for `sandboxId`, or the account client when it is undefined. `module` is untrusted:
90
+ * use it through {@link sdkConstruct} and {@link sdkCall}, which throw `invalid_argument` when an export or method is missing.
91
+ */
92
+ connect(module: SdkValue, sandboxId: string | undefined): object | Promise<object>;
93
+ }
94
+ /** A member of the caller's SDK module, or of an object it built, read by name and checked before use. */
95
+ export type SdkMember = SdkValue | JsonValue | undefined;
96
+ /** A module, class, function or object from the caller's SDK. */
97
+ export interface SdkValue {
98
+ readonly [member: string]: SdkMember;
99
+ }
100
+ /** `value` when the SDK returned an object, else `invalid_argument` naming the package. */
101
+ export declare function sdkObject(value: SdkMember, what: string, packageName: string): SdkValue;
102
+ /** Options for {@link createNativeApi}. */
103
+ export interface NativeApiOptions<Plane extends string> {
104
+ /** The adapter's HTTP client. Its planes, credentials, retries, redaction and error hooks apply to native calls too. */
105
+ http: HttpClient<Plane>;
106
+ /** The placeholder(s) `box.native` fills from the sandbox ID, without braces: `"sandboxId"`, or several names when the provider's docs use more than one. */
107
+ placeholder: string | readonly string[];
108
+ /** Bind to this sandbox (`box.native`). Leave it out for `provider.api`. */
109
+ sandboxId?: string;
110
+ /** How `sdk(load)` connects. Without it, `sdk()` rejects with `unsupported`. */
111
+ sdk?: NativeSdkBinding;
112
+ }
113
+ /**
114
+ * Builds `box.native` (with `sandboxId`) or `provider.api` (without) on top of an adapter's HTTP client.
115
+ * `Sdk` is the provider's loader type; the runtime binding checks the module's shape.
116
+ */
117
+ export declare function createNativeApi<Plane extends string, Sdk extends NativeSdkLoader = AnyNativeSdk>(options: NativeApiOptions<Plane>): NativeApi<Plane, Sdk>;
118
+ /**
119
+ * `new module[name](...args)` for a module handed to `native.sdk()`. Throws `invalid_argument` naming
120
+ * the package when the export is missing or is not a class.
121
+ */
122
+ export declare function sdkConstruct(module: SdkValue, name: string, args: unknown[], packageName: string): SdkValue;
123
+ /**
124
+ * `target[name](...args)` on an object from the caller's SDK, awaited. Throws `invalid_argument` naming
125
+ * the package when the method is missing, which means the installed SDK version does not match.
126
+ */
127
+ export declare function sdkCall(target: SdkMember, name: string, args: unknown[], packageName: string): Promise<SdkMember>;
package/dist/openai.js CHANGED
@@ -1 +1 @@
1
- import"./chunk-t5vr9nd8.js";import{w}from"./chunk-v6y7eqxw.js";import"./chunk-cwx6cc31.js";import{tool as r}from"@openai/agents";function m(t,e){return w(t,e).map((o)=>r({name:o.name,description:o.description,parameters:o.inputSchema,strict:!0,execute:async(s,n,a)=>(await o.execute(s,void 0,a?.signal)).text}))}export{m as sandboxTools};
1
+ import"./chunk-23tjmd39.js";import{M}from"./chunk-nw845a93.js";import"./chunk-ckym4cht.js";import{tool as r}from"@openai/agents";function m(t,e){return M(t,e).map((o)=>r({name:o.name,description:o.description,parameters:o.inputSchema,strict:!0,execute:async(s,n,a)=>(await o.execute(s,void 0,a?.signal)).text}))}export{m as sandboxTools};
package/dist/peer.d.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  /** Loads an optional peer SDK on first use. A missing install becomes an
2
2
  * unavailable error naming the package, instead of the adapter's generic
3
3
  * provider failure. Callers pass a literal import() so bundlers keep it external.
4
+ * The result goes through {@link peerModule}, so named exports work in bundles too.
4
5
  */
5
6
  export declare function loadPeer<T>(name: string, provider: string, load: () => Promise<T>): Promise<T>;
7
+ /** Normalizes a dynamically imported CommonJS peer. Bundlers that split chunks
8
+ * (esbuild with splitting, as Convex uses) give `import()` of a CommonJS package
9
+ * a namespace whose only export is `default`, the original `module.exports`.
10
+ * Named exports missing from the namespace are filled in from `default`, and
11
+ * exports the namespace already has win. A namespace that lacks nothing is
12
+ * returned as is.
13
+ */
14
+ export declare function peerModule<T>(module: T): T;
@@ -60,11 +60,26 @@ export interface FileInfo {
60
60
  size: number;
61
61
  modifiedAt: number;
62
62
  }
63
+ /** Options for one file write. */
64
+ export interface WriteOptions {
65
+ /** POSIX permission bits for the file, such as `0o600`. */
66
+ mode?: number;
67
+ }
68
+ /** Options for {@link Provider.snapshot}. */
69
+ export interface SnapshotOptions {
70
+ /** Delete the snapshot after this many milliseconds. `0` keeps it until you delete it, where the provider allows that. */
71
+ expiresInMs?: number;
72
+ }
63
73
  export interface ProviderFiles {
64
- /** Use primitive file transfers when guest tar is incompatible with GNU archives. */
74
+ /** Use primitive file transfers when guest tar is missing or incompatible with GNU archives. */
65
75
  readonly transfer?: "files";
76
+ /** Record mark() and changes() checkpoints by reading every workspace file instead of
77
+ * running guest git. For runtimes without git; each call reads the whole workspace. */
78
+ readonly checkpoints?: "files";
66
79
  /** Write handles missing parents itself, avoiding an unconditional mkdir RPC. */
67
80
  readonly writeCreatesParents?: boolean;
81
+ /** Write applies `options.mode` itself. Without it, the core runs `chmod` after the write. */
82
+ readonly writeSupportsMode?: boolean;
68
83
  /** Top-level /workspace entries the provider itself owns. File checkpoints and changes() skip them. */
69
84
  readonly internal?: readonly string[];
70
85
  readRange?(id: string, path: string, options: {
@@ -72,7 +87,7 @@ export interface ProviderFiles {
72
87
  length: number;
73
88
  }): Promise<Uint8Array>;
74
89
  read(id: string, path: string): Promise<Uint8Array>;
75
- write(id: string, path: string, data: Uint8Array): Promise<void>;
90
+ write(id: string, path: string, data: Uint8Array, options?: WriteOptions): Promise<void>;
76
91
  list(id: string, path: string): Promise<FileInfo[]>;
77
92
  stat(id: string, path: string): Promise<FileInfo>;
78
93
  remove(id: string, path: string, options: {
@@ -105,8 +120,14 @@ export interface NativeProcess {
105
120
  export interface Provider<Native = unknown, C extends Capability = Capability> {
106
121
  readonly name: string;
107
122
  readonly keyMode: "exact" | "best-effort";
108
- /** Omission uses native hooks or the portable shell process-record shim. */
109
- readonly processMode?: "shell" | "unsupported";
123
+ /** Omission uses native hooks or the portable shell process-record shim. "stream" is for
124
+ * runtimes without a POSIX shell: startProcess runs the command itself and streams its
125
+ * output, and the core keeps the process records with file calls. Those logs stop when
126
+ * the client that started the process goes away. */
127
+ readonly processMode?: "shell" | "stream" | "unsupported";
128
+ /** "placeholder": preview URLs are never served. Port readiness holds once the URL is
129
+ * issued, without an HTTP probe. */
130
+ readonly previewMode?: "placeholder";
110
131
  /** Exec creates/removes input.activityPath without separate file RPCs. */
111
132
  readonly inlineActivity?: boolean;
112
133
  /** Native command dialect for portable run wrappers; defaults to POSIX sh. */
@@ -127,7 +148,7 @@ export interface Provider<Native = unknown, C extends Capability = Capability> {
127
148
  usage?(id: string): Promise<Record<string, number>>;
128
149
  pause?(id: string): Promise<void>;
129
150
  resume?(id: string): Promise<void>;
130
- snapshot?(id: string): Promise<{
151
+ snapshot?(id: string, options?: SnapshotOptions): Promise<{
131
152
  id: string;
132
153
  }>;
133
154
  terminal?(id: string, options: {
@@ -135,4 +156,16 @@ export interface Provider<Native = unknown, C extends Capability = Capability> {
135
156
  rows: number;
136
157
  }): Promise<Terminal>;
137
158
  startProcess?(id: string, input: Omit<ExecInput, "timeoutMs">): Promise<NativeProcess>;
159
+ /** Secret recovery without a shell, for runtimes that cannot run the core's recovery
160
+ * command. Return the text of /tmp/.sandbox-sdk/secret-names.json and the environment a
161
+ * new command starts with, or undefined when that file does not exist. The core validates
162
+ * the record. Without this hook, the core reads both with one shell command. */
163
+ readSecretEnvironment?(id: string): Promise<{
164
+ record: string;
165
+ environment: Record<string, string>;
166
+ } | undefined>;
138
167
  }
168
+ export { createHttpClient, createDeadline } from "./http.js";
169
+ export type { HttpClient, HttpClientOptions, HttpPlane, HttpRequest, StreamRequest, HttpResponse, HttpFailure, FailedRequest, ErrorBody, PlaneContext, Fetch, Deadline, StaleVerdict, } from "./http.js";
170
+ export { createNativeApi, sdkConstruct, sdkCall } from "./native.js";
171
+ export type { NativeApi, NativeApiOptions, NativeSdkBinding, NativeRequestOptions, NativeSdkLoader, AnyNativeSdk, HttpMethod, } from "./native.js";
package/dist/provider.js CHANGED
@@ -0,0 +1 @@
1
+ import{d,x,h,v,k}from"./chunk-vy1j4r8f.js";export{d as createDeadline,x as createHttpClient,h as createNativeApi,k as sdkCall,v as sdkConstruct};
@@ -1,4 +1,5 @@
1
1
  import { SandboxError, type ErrorCode } from "../../errors.js";
2
- export declare function failure(message: string, code?: ErrorCode, sandboxId?: string): SandboxError;
3
- /** Native errors may include file contents, environment variables, or credentials. */
2
+ export declare function failure(message: string, code?: ErrorCode, sandboxId?: string, cause?: string): SandboxError;
3
+ /** Native errors may include file contents or environment variables. Only an unrecognized failure keeps
4
+ * its text (see describeNative), scrubbed here; the core redacts registered secrets from it too. */
4
5
  export declare function agentosError(cause: unknown, sandboxId?: string, file?: boolean): SandboxError;
@@ -1,11 +1,4 @@
1
- import type { AgentOs } from "@rivet-dev/agentos-core";
2
- import type { Provider } from "../../provider.js";
3
- export interface AgentosOptions {
4
- /** Trusted local .aospkg file; otherwise install Rivet's pinned Git release. */
5
- gitPackagePath?: string;
6
- }
7
- type AgentosCapability = "network-policy";
8
- export type AgentosProvider = Provider<AgentOs, AgentosCapability>;
1
+ import { type AgentosOptions, type AgentosProvider } from "./provider.js";
2
+ export type { AgentosOptions, AgentosProvider } from "./provider.js";
9
3
  /** Embedded, Docker-free V8/WebAssembly runtime. Docker remains local()'s default. */
10
4
  export declare function agentos(options?: AgentosOptions): AgentosProvider;
11
- export {};
@@ -1,2 +1,2 @@
1
- import{e}from"../../chunk-gc8zdxyb.js";import{randomUUID as S}from"node:crypto";import{posix as k}from"node:path";function l(o,i="provider",m){return new e(`${o}. Check the agentOS runtime or use local() with Docker.`,{code:i,provider:"agentos",sandboxId:m})}function x(o,i,m=!1){if(o instanceof e)return o;let d=o instanceof Error?o.message:"",c=/ENOENT|not found|no such file/i.test(d)?m?"file_not_found":"not_found":/limit|quota|ENOSPC/i.test(d)?"quota":/sidecar.*(exit|closed|missing)|cannot find package|module not found/i.test(d)?"unavailable":/EACCES|EPERM|invalid|EINVAL/i.test(d)?"invalid_argument":"provider";return l(`agentOS operation failed (${c})`,c,i)}var w=new Map,h=new Map,A=new Map,P="sha256:35ae142556050de3604342574494373c318adff3ac3b50ea6b7420c0a033d2d8",E=`https://releases.rivet.dev/agent-os/0.4.1/software/packages/git/${P.slice(7)}.aospkg`;function b(o){let i=w.get(o);if(!i)throw l("Sandbox does not exist in this application process","not_found",o);return i}function v(o){return{...o,labels:{...o.labels}}}var C=(o)=>`'${o.replace(/'/g,"'\\''")}'`;function I(o,i){return{path:o,type:i.isSymbolicLink?"symlink":i.isDirectory?"directory":"file",size:i.size,modifiedAt:i.mtimeMs}}async function O(o,i,m){if(!(m??(i!=="/"&&(await o.filesystem.readdirEntries(k.dirname(i))).find((t)=>t.name===k.basename(i))?.isSymbolicLink)))return I(i,await o.filesystem.stat(i));let c=await o.javascript.evaluate(`(() => { const s = require("node:fs").lstatSync(${JSON.stringify(i)}); return { size: s.size, modifiedAt: s.mtimeMs }; })()`);if(c.outcome!=="succeeded"||!c.value||typeof c.value!=="object"||Array.isArray(c.value)||typeof c.value.size!=="number"||typeof c.value.modifiedAt!=="number")throw l("agentOS could not read symbolic link metadata","provider");return{path:i,type:"symlink",size:c.value.size,modifiedAt:c.value.modifiedAt}}function j(o={}){let i,m=()=>i??=import("@rivet-dev/agentos-core").catch(()=>{throw l("Install @rivet-dev/agentos-core@0.4.1 and its platform sidecar package","unavailable")});async function d(t,n,r=!1){try{return await n(b(t).vm)}catch(s){throw x(s,t,r)}}let c={name:"agentos",inlineActivity:!0,keyMode:"exact",processMode:"unsupported",capabilities:new Set(["network-policy"]),async create(t){if(t.size!==void 0||t.from!==void 0)throw l("agentOS cannot enforce machine sizes or restore SDK snapshots","unsupported");if(t.idleTimeoutMs!==void 0||t.timeoutMs!==void 0)throw l("agentOS adapter does not enforce sandbox lifetime or idle deadlines","unsupported");if(t.signal?.aborted)throw l("Creation aborted","aborted");let n=t.network??"all",r={network:n==="none"?"deny":"allow"};if(typeof n==="object"){for(let a of n.allow)if(!/^(?=.{1,253}$)[a-zA-Z0-9](?:[a-zA-Z0-9.-]*[a-zA-Z0-9])?$/.test(a))throw l("Network allow-list entries must be literal hostnames","unsupported");r={network:{default:"deny",rules:n.allow.map((a)=>({mode:"allow",operations:["*"],patterns:[`dns://${a}`,`tcp://${a}:*`]}))}}}async function s(){let a;try{let{AgentOs:u}=await m();if(a=await u.create({permissions:r,...Object.keys(t.env??{}).length?{environment:{PATH:"/opt/agentos/bin:/usr/local/bin:/usr/bin:/bin",HOME:"/home/agentos",...t.env}}:{}}),await a.software.install(o.gitPackagePath?{type:"path",path:o.gitPackagePath}:{type:"url",url:E,expectedDigest:P}),await a.filesystem.mkdir("/workspace",{recursive:!0}),t.signal?.aborted)throw l("Creation aborted","aborted");let f={id:`agentos-${S()}`,key:t.key,labels:{...t.labels,"sandbox-sdk":"1"},state:"running",createdAt:Date.now()};return w.set(f.id,{vm:a,info:f}),v(f)}catch(u){if(a)await a.dispose().catch(()=>{});throw x(u)}}if(!t.key)return s();if(await c.find(t.key))throw l("Key already exists in this application process","invalid_argument");let g=h.get(t.key);if(g)throw await g,l("Key was created concurrently in this application process","invalid_argument");let y=s();h.set(t.key,y);try{return await y}finally{h.delete(t.key)}},async find(t){for(let n of w.values())if(n.info.key===t)return v(n.info);return},async connect(t){return v(b(t).info)},async list(t){return[...w.values()].filter((n)=>Object.entries(t).every(([r,s])=>n.info.labels[r]===s)).map((n)=>v(n.info))},async destroy(t){if(!w.get(t))return;let r=A.get(t);if(r)return r;let s=d(t,(p)=>p.dispose()).then(()=>{w.delete(t)});A.set(t,s);try{await s}finally{A.delete(t)}},async exec(t,n){if(n.signal?.aborted)return{exitCode:null,timedOut:!0};return d(t,async(r)=>{let s=new TextDecoder,p=new TextDecoder,g=`/tmp/.sandbox-sdk/stdin-${S()}`;if(n.stdin!==void 0)await r.filesystem.mkdir("/tmp/.sandbox-sdk",{recursive:!0}),await r.filesystem.writeFile(g,n.stdin);try{if(n.signal?.aborted)return{exitCode:null,timedOut:!0};let y=await r.process.exec(`exec < ${n.stdin===void 0?"/dev/null":C(g)}
2
- ${n.command}`,{cwd:n.cwd,env:n.env,timeoutMs:n.timeoutMs,signal:n.signal,output:{capture:"none"},onStdout(u){let f=s.decode(u,{stream:!0});if(f)n.onChunk({stream:"stdout",text:f})},onStderr(u){let f=p.decode(u,{stream:!0});if(f)n.onChunk({stream:"stderr",text:f})}});for(let[u,f]of[["stdout",s.decode()],["stderr",p.decode()]])if(f)n.onChunk({stream:u,text:f});let a=y.outcome==="timed_out"||y.outcome==="cancelled";if(!a&&y.exitCode===void 0)throw l("agentOS did not report a command exit","outcome_unknown",t);return{exitCode:a?null:y.exitCode??null,timedOut:a}}finally{if(n.stdin!==void 0)await r.filesystem.remove(g).catch(()=>{})}})},files:{writeCreatesParents:!0,transfer:"files",read:(t,n)=>d(t,async(r)=>new Uint8Array(await r.filesystem.readFile(n)),!0),write:(t,n,r)=>d(t,async(s)=>{await s.filesystem.mkdir(k.dirname(n),{recursive:!0}),await s.filesystem.writeFile(n,r)},!0),stat:(t,n)=>d(t,async(r)=>O(r,n),!0),list:(t,n)=>d(t,async(r)=>Promise.all((await r.filesystem.readdirEntries(n)).map((s)=>O(r,k.join(n,s.name),s.isSymbolicLink))),!0),mkdir:(t,n)=>d(t,(r)=>r.filesystem.mkdir(n,{recursive:!0}),!0),remove:(t,n,r)=>d(t,(s)=>s.filesystem.remove(n,r),!0)},async previewUrl(t){throw b(t),l("Embedded agentOS has no preview URLs; forward HTTP with native.network.httpRequest","unsupported",t)},native(t){return b(t).vm}};return c}export{j as agentos};
1
+ import{m}from"../../chunk-bd481sb7.js";import{g}from"../../chunk-k60b4r27.js";import{n}from"../../chunk-2ts3evzh.js";import{e,w,i,a}from"../../chunk-xgxfy2n8.js";import{randomUUID as I}from"node:crypto";import{posix as V}from"node:path";function u(o,d="provider",p,l){return new e(`${o}. Check the agentOS runtime or use local() with Docker.`,{code:d,provider:"agentos",sandboxId:p,cause:l})}function E(o,d,p=!1){if(o instanceof e)return o;let{message:l}=m(o),k=/ENOENT|not found|no such file/i.test(l)?p?"file_not_found":"not_found":/limit|quota|ENOSPC/i.test(l)?"quota":/sidecar.*(exit|closed|missing)|cannot find package|module not found/i.test(l)?"unavailable":/EACCES|EPERM|invalid|EINVAL/i.test(l)?"invalid_argument":"provider",b=i(o,{code:k});return u(`agentOS operation failed: ${a(k,b.detail)}`,k,d,b.cause)}function D(){return{entries:new Map,keys:new Map,destroying:new Map}}var R="sha256:35ae142556050de3604342574494373c318adff3ac3b50ea6b7420c0a033d2d8",j=`https://releases.rivet.dev/agent-os/0.4.1/software/packages/git/${R.slice(7)}.aospkg`;function S(o){return{...o,labels:{...o.labels}}}function F(o,d){let p="file";if(d.isSymbolicLink)p="symlink";else if(d.isDirectory)p="directory";return{path:o,type:p,size:d.size,modifiedAt:d.mtimeMs}}function _(o){return typeof o==="object"&&o!==null&&!Array.isArray(o)&&typeof o.size==="number"&&typeof o.modifiedAt==="number"}async function z(o,d,p){if(!(p??(d!=="/"&&(await o.filesystem.readdirEntries(V.dirname(d))).find((b)=>b.name===V.basename(d))?.isSymbolicLink)))return F(d,await o.filesystem.stat(d));let k=await o.javascript.evaluate(`(() => { const s = require("node:fs").lstatSync(${JSON.stringify(d)}); return { size: s.size, modifiedAt: s.mtimeMs }; })()`);if(k.outcome!=="succeeded"||!_(k.value))throw u("agentOS could not read symbolic link metadata","provider");return{path:d,type:"symlink",size:k.value.size,modifiedAt:k.value.modifiedAt}}async function q(o,d,p){let l=await o.javascript.evaluate(`(() => { require("node:fs").chmodSync(${JSON.stringify(d)}, ${p}); return true; })()`);if(l.outcome!=="succeeded"||l.value!==!0)throw u("agentOS could not set the file mode","provider")}function T(o,d,p){let{entries:l,keys:k,destroying:b}=p,L,N=()=>L??=g("@rivet-dev/agentos-core","agentos",d).catch((t)=>{throw u("Install @rivet-dev/agentos-core@0.4.1 and its platform sidecar package","unavailable",void 0,w(t))});function P(t){let r=l.get(t);if(!r)throw u("Sandbox does not exist in this application process","not_found",t);return r}async function x(t,r,s=!1){try{return await r(P(t).vm)}catch(c){throw E(c,t,s)}}let M={name:"agentos",inlineActivity:!0,keyMode:"exact",processMode:"unsupported",capabilities:new Set(["network-policy"]),async create(t){if(t.size!==void 0||t.from!==void 0)throw u("agentOS cannot enforce machine sizes or restore SDK snapshots","unsupported");if(t.idleTimeoutMs!==void 0||t.timeoutMs!==void 0)throw u("agentOS adapter does not enforce sandbox lifetime or idle deadlines","unsupported");if(t.signal?.aborted)throw u("Creation aborted","aborted");let r=t.network??"all",s={network:r==="none"?"deny":"allow"};if(r!=="all"&&r!=="none"){for(let f of r.allow)if(!/^(?=.{1,253}$)[a-zA-Z0-9](?:[a-zA-Z0-9.-]*[a-zA-Z0-9])?$/.test(f))throw u("Network allow-list entries must be literal hostnames","unsupported");s={network:{default:"deny",rules:r.allow.map((f)=>({mode:"allow",operations:["*"],patterns:[`dns://${f}`,`tcp://${f}:*`]}))}}}async function c(){let f;try{let{AgentOs:A}=await N(),y={permissions:s};if(Object.keys(t.env??{}).length)y.environment={PATH:"/opt/agentos/bin:/usr/local/bin:/usr/bin:/bin",HOME:"/home/agentos",...t.env};if(o.software?.length)y.software=o.software;if(o.mounts?.length)y.mounts=o.mounts;if(o.limits)y.limits=o.limits;if(f=await A.create(y),await f.software.install(o.gitPackagePath?{type:"path",path:o.gitPackagePath}:{type:"url",url:j,expectedDigest:R}),await f.filesystem.mkdir("/workspace",{recursive:!0}),t.signal?.aborted)throw u("Creation aborted","aborted");let C={id:`agentos-${I()}`,key:t.key,labels:{...t.labels,"sandbox-sdk":"1"},state:"running",createdAt:Date.now()};return l.set(C.id,{vm:f,info:C}),S(C)}catch(A){if(f)await f.dispose().catch(()=>{});throw E(A)}}if(!t.key)return c();if(await M.find(t.key))throw u("Key already exists in this application process","invalid_argument");let h=k.get(t.key);if(h)throw await h,u("Key was created concurrently in this application process","invalid_argument");let O=c();k.set(t.key,O);try{return await O}finally{k.delete(t.key)}},async find(t){for(let r of l.values())if(r.info.key===t)return S(r.info);return},async connect(t){return S(P(t).info)},async list(t){return[...l.values()].flatMap((r)=>Object.entries(t).every(([s,c])=>r.info.labels[s]===c)?[S(r.info)]:[])},async destroy(t){if(!l.get(t))return;let s=b.get(t);if(s)return s;let c=x(t,(v)=>v.dispose()).then(()=>{l.delete(t)});b.set(t,c);try{await c}finally{b.delete(t)}},async exec(t,r){if(r.signal?.aborted)return{exitCode:null,timedOut:!0};return x(t,async(s)=>{let c=new TextDecoder,v=new TextDecoder,h=`/tmp/.sandbox-sdk/stdin-${I()}`;if(r.stdin!==void 0)await s.filesystem.mkdir("/tmp/.sandbox-sdk",{recursive:!0}),await s.filesystem.writeFile(h,r.stdin);try{if(r.signal?.aborted)return{exitCode:null,timedOut:!0};let O=await s.process.exec(`exec < ${r.stdin===void 0?"/dev/null":n(h)}
2
+ ${r.command}`,{cwd:r.cwd,env:r.env,timeoutMs:r.timeoutMs,signal:r.signal,output:{capture:"none"},onStdout(A){let y=c.decode(A,{stream:!0});if(y)r.onChunk({stream:"stdout",text:y})},onStderr(A){let y=v.decode(A,{stream:!0});if(y)r.onChunk({stream:"stderr",text:y})}});for(let[A,y]of[["stdout",c.decode()],["stderr",v.decode()]])if(y)r.onChunk({stream:A,text:y});let f=O.outcome==="timed_out"||O.outcome==="cancelled";if(!f&&O.exitCode===void 0)throw u("agentOS did not report a command exit","outcome_unknown",t);return{exitCode:f?null:O.exitCode??null,timedOut:f}}finally{if(r.stdin!==void 0)await s.filesystem.remove(h).catch(()=>{})}})},files:{writeCreatesParents:!0,writeSupportsMode:!0,transfer:"files",read:(t,r)=>x(t,async(s)=>new Uint8Array(await s.filesystem.readFile(r)),!0),write:(t,r,s,c)=>x(t,async(v)=>{if(await v.filesystem.mkdir(V.dirname(r),{recursive:!0}),await v.filesystem.writeFile(r,s),c?.mode!==void 0)await q(v,r,c.mode)},!0),stat:(t,r)=>x(t,async(s)=>z(s,r),!0),list:(t,r)=>x(t,async(s)=>Promise.all((await s.filesystem.readdirEntries(r)).map((c)=>z(s,V.join(r,c.name),c.isSymbolicLink))),!0),mkdir:(t,r)=>x(t,(s)=>s.filesystem.mkdir(r,{recursive:!0}),!0),remove:(t,r,s)=>x(t,(c)=>c.filesystem.remove(r,s),!0)},async previewUrl(t){throw P(t),u("Embedded agentOS has no preview URLs; forward HTTP with native.network.httpRequest","unsupported",t)},native(t){return P(t).vm}};return M}var U=D();function te(o={}){return T(o,()=>import("@rivet-dev/agentos-core"),U)}export{te as agentos};
@@ -0,0 +1,50 @@
1
+ import type { AgentOs, AgentOsOptions, InstalledSoftware, JsonValue, ReaddirEntry, SoftwarePackageSource, VirtualStat } from "@rivet-dev/agentos-core";
2
+ import type { Provider, SandboxInfo } from "../../provider.js";
3
+ export interface AgentosOptions {
4
+ /** Trusted local .aospkg file; otherwise install Rivet's pinned Git release. */
5
+ gitPackagePath?: string;
6
+ /** Extra agentOS software packages, installed with Core's default tools and Git. Default: none. */
7
+ software?: AgentOsOptions["software"];
8
+ /** Boot-time mounts, such as `hostDirMount("/data", "/srv/data")` from agentOS Core. Read-only unless the mount says otherwise. Default: none. */
9
+ mounts?: AgentOsOptions["mounts"];
10
+ /** Kernel resource limits (processes, open files, filesystem bytes, WASM memory and fuel). Default: Core's built-in limits. */
11
+ limits?: AgentOsOptions["limits"];
12
+ }
13
+ type AgentosCapability = "network-policy";
14
+ /** The parts of an agentOS VM the adapter uses. */
15
+ export type AgentosVm = Pick<AgentOs, "dispose"> & {
16
+ filesystem: Pick<AgentOs["filesystem"], "readFile" | "writeFile" | "mkdir" | "remove"> & {
17
+ stat(path: string): Promise<Pick<VirtualStat, "size" | "mtimeMs" | "isDirectory" | "isSymbolicLink">>;
18
+ readdirEntries(path: string): Promise<Pick<ReaddirEntry, "name" | "isSymbolicLink">[]>;
19
+ };
20
+ process: Pick<AgentOs["process"], "exec">;
21
+ javascript: {
22
+ evaluate(expression: string): Promise<{
23
+ outcome: string;
24
+ value?: JsonValue;
25
+ }>;
26
+ };
27
+ software: {
28
+ install(source: SoftwarePackageSource): Promise<Pick<InstalledSoftware, "packageName">>;
29
+ };
30
+ };
31
+ /** The parts of agentOS Core the adapter uses: the real module, or a test fixture. */
32
+ export interface AgentosModule<V extends AgentosVm> {
33
+ AgentOs: {
34
+ create(options: AgentOsOptions): Promise<V>;
35
+ };
36
+ }
37
+ /** VMs by sandbox ID, plus in-flight keyed creates and destroys. */
38
+ export interface AgentosRegistry<V extends AgentosVm> {
39
+ entries: Map<string, {
40
+ vm: V;
41
+ info: SandboxInfo;
42
+ }>;
43
+ keys: Map<string, Promise<SandboxInfo>>;
44
+ destroying: Map<string, Promise<void>>;
45
+ }
46
+ export declare function createRegistry<V extends AgentosVm>(): AgentosRegistry<V>;
47
+ export type AgentosProvider = Provider<AgentOs, AgentosCapability>;
48
+ /** @internal The adapter behind `agentos()`. `load` imports agentOS Core; VMs live in `registry`. */
49
+ export declare function createAgentosProvider<V extends AgentosVm>(options: AgentosOptions, load: () => Promise<AgentosModule<V>>, registry: AgentosRegistry<V>): Provider<V, AgentosCapability>;
50
+ export {};
@@ -1,6 +1,24 @@
1
- import type { BoatApi, CreateSandboxRequest, Sandbox as BoatSandbox } from "@boatdev/sdk";
1
+ import type { BoatPlane } from "../boat-api/transport.js";
2
+ import type { NativeApi } from "../../native.js";
2
3
  import type { Provider } from "../../provider.js";
3
- export interface BoatOptions {
4
+ /** Boat machine types: 2 CPU/4 GB, 4 CPU/8 GB, 8 CPU/16 GB, 16 CPU/32 GB. */
5
+ export type BoatMachine = "small" | "default" | "large" | "xlarge";
6
+ /** Native create fields shared by Boat and Sandboxer. */
7
+ export interface BoatCreateOptions {
8
+ /** Seconds until the VM auto-stops; `null` turns auto-stop off. Default: 3600.
9
+ * At most 2592000. The timer restarts while the provider's own agent works,
10
+ * so this caps idle cost but is not a hard lifetime. */
11
+ ttlSeconds?: number | null;
12
+ /** `false` never snapshots the VM: it pays nothing for background captures,
13
+ * and a stop erases its disk. Default: true. */
14
+ snapshots?: boolean;
15
+ /** `false` keeps no command output, process list, or metrics at the provider.
16
+ * Live output still streams. Default: the account setting. */
17
+ monitoring?: boolean;
18
+ /** Organization to bill, by id or name. Default: your active wallet. */
19
+ org?: string;
20
+ }
21
+ export interface BoatOptions extends BoatCreateOptions {
4
22
  /** Defaults to BOAT_API_KEY; required on first use. */
5
23
  apiKey?: string;
6
24
  /** Defaults to BOAT_API_BASE, then https://boat.dev/api/v1. */
@@ -8,16 +26,41 @@ export interface BoatOptions {
8
26
  /** @deprecated Use baseUrl. Removed in 1.0.0. */
9
27
  apiUrl?: string;
10
28
  /** Native machine size; default: Boat default (4 CPU/8 GB). Per-create size wins. */
11
- machine?: CreateSandboxRequest["type"];
29
+ machine?: BoatMachine;
12
30
  /** @deprecated Use machine. Removed in 1.0.0. */
13
- type?: CreateSandboxRequest["type"];
31
+ type?: BoatMachine;
14
32
  /** Deadline for each control-plane request. Default: 90 seconds. */
15
33
  requestTimeoutMs?: number;
16
34
  }
17
- export interface BoatNative {
18
- readonly sandbox: BoatSandbox;
19
- readonly client: BoatApi;
35
+ /** What `native.sdk()` needs from `@boatdev/sdk`: its `Configuration` and `BoatApi` classes. */
36
+ export interface BoatSdkModule {
37
+ Configuration: new (parameters: {
38
+ basePath?: string;
39
+ accessToken?: string;
40
+ }) => object;
41
+ BoatApi: new (configuration: never) => {
42
+ get(request: {
43
+ sandboxId: string;
44
+ }): Promise<{
45
+ sandbox: unknown;
46
+ }>;
47
+ };
20
48
  }
21
- export type BoatProvider = Provider<BoatNative, "size">;
22
- /** Direct optional SDK with no installed remote agent or local daemon. */
49
+ /** `box.native.sdk(() => import("@boatdev/sdk"))`: a `BoatApi` client with this adapter's base URL and key, and the sandbox's metadata from `client.get`. */
50
+ export type BoatSandboxSdk = <M extends BoatSdkModule>(load: () => Promise<M>) => Promise<{
51
+ client: InstanceType<M["BoatApi"]>;
52
+ sandbox: Awaited<ReturnType<InstanceType<M["BoatApi"]>["get"]>>["sandbox"];
53
+ }>;
54
+ /** `provider.api.sdk(() => import("@boatdev/sdk"))`: the `BoatApi` client. */
55
+ export type BoatClientSdk = <M extends BoatSdkModule>(load: () => Promise<M>) => Promise<InstanceType<M["BoatApi"]>>;
56
+ /**
57
+ * `box.native`: Boat's HTTP API with this adapter's base URL, key, retries and redaction. Its one plane is
58
+ * `"api"`, and `{sandboxId}` in a path fills from the sandbox.
59
+ */
60
+ export type BoatNative = NativeApi<BoatPlane, BoatSandboxSdk>;
61
+ export type BoatProvider = Provider<BoatNative, "size"> & {
62
+ /** Boat's API with no sandbox bound, for account calls such as `GET /limits`. */
63
+ readonly api: NativeApi<BoatPlane, BoatClientSdk>;
64
+ };
65
+ /** Boat API v1 over plain HTTP. No other package to install. */
23
66
  export declare function boat(options?: BoatOptions): BoatProvider;
@@ -1 +1 @@
1
- import"../../chunk-t5vr9nd8.js";import{x}from"../../chunk-yrsb6hws.js";function o(e={}){return x(e)}export{o as boat};
1
+ import"../../chunk-23tjmd39.js";import{q}from"../../chunk-gw3n7sx7.js";function o(e={}){return q(e).provider}export{o as boat};
@@ -1,11 +1,24 @@
1
- import type { BoatApi } from "@boatdev/sdk";
2
1
  import type { ExecInput, ExecResult } from "../../provider.js";
2
+ import { errors } from "./errors.js";
3
+ import { type FollowTiming } from "./follow.js";
4
+ import { type BoatHttp } from "./transport.js";
3
5
  export declare const workspace = "flock -x /tmp/.sandbox-sdk-workspace-ready.lock sh -c 'if [ ! -f /tmp/.sandbox-sdk/prepared-workspace ]; then sudo mkdir -p /workspace && sudo chown \"$(id -u):$(id -g)\" /workspace && command -v node git tar setsid nohup mkfifo sed base64 >/dev/null && mkdir -p /tmp/.sandbox-sdk && touch /tmp/.sandbox-sdk/prepared-workspace || exit 1; fi' || exit 1";
4
6
  export declare const quote: (value: string) => string;
7
+ /** Boat's file API accepts at most 5 MiB per write, after decoding, and only
8
+ * under /home/user or /tmp. Keep a margin below that limit. */
9
+ export declare const fileChunkBytes: number;
10
+ /** Upload bytes into a new private directory as `part-N` files. The directory
11
+ * is 0700 and every part exists as an empty 0600 file before its bytes arrive.
12
+ * Bytes travel only through the file API, never through command text. The
13
+ * caller owns `dir` and removes it, including after a failure. */
14
+ export declare function stage(http: BoatHttp, id: string, dir: string, data: Uint8Array, failure: ReturnType<typeof errors>["failure"]): Promise<string[]>;
5
15
  /** Detached commands have no 600-second limit. Boat's stopCommand kills the
6
16
  * command and all descendants. Aborting a stream alone does not stop remote work.
7
17
  */
8
- export declare function execute(api: BoatApi, id: string, input: ExecInput, sandboxEnv?: Record<string, string>, environmentFiles?: Map<string, Promise<string>>, diagnostics?: {
18
+ export declare function execute(http: BoatHttp, id: string, input: ExecInput, sandboxEnv?: Record<string, string>, environmentFiles?: Map<string, Promise<string>>, diagnostics?: {
9
19
  boatError: (cause: unknown, sandboxId?: string) => import("../../errors.js").SandboxError;
10
20
  failure: (message: string, code?: import("../../errors.js").ErrorCode, sandboxId?: string) => import("../../errors.js").SandboxError;
21
+ }, follow?: {
22
+ http?: BoatHttp;
23
+ timing?: FollowTiming;
11
24
  }): Promise<ExecResult>;