@strands-agents/sdk 1.4.0 → 1.5.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/README.md +11 -11
- package/dist/src/__fixtures__/agent-helpers.d.ts.map +1 -1
- package/dist/src/__fixtures__/agent-helpers.js +6 -0
- package/dist/src/__fixtures__/agent-helpers.js.map +1 -1
- package/dist/src/__fixtures__/register-node-defaults.d.ts +2 -0
- package/dist/src/__fixtures__/register-node-defaults.d.ts.map +1 -0
- package/dist/src/__fixtures__/register-node-defaults.js +6 -0
- package/dist/src/__fixtures__/register-node-defaults.js.map +1 -0
- package/dist/src/__fixtures__/test-sandbox.node.d.ts.map +1 -1
- package/dist/src/__fixtures__/test-sandbox.node.js +4 -3
- package/dist/src/__fixtures__/test-sandbox.node.js.map +1 -1
- package/dist/src/__tests__/default-slot.test.d.ts +2 -0
- package/dist/src/__tests__/default-slot.test.d.ts.map +1 -0
- package/dist/src/__tests__/default-slot.test.js +33 -0
- package/dist/src/__tests__/default-slot.test.js.map +1 -0
- package/dist/src/a2a/__tests__/async-lock.test.d.ts +2 -0
- package/dist/src/a2a/__tests__/async-lock.test.d.ts.map +1 -0
- package/dist/src/a2a/__tests__/async-lock.test.js +137 -0
- package/dist/src/a2a/__tests__/async-lock.test.js.map +1 -0
- package/dist/src/a2a/__tests__/executor.test.js +146 -8
- package/dist/src/a2a/__tests__/executor.test.js.map +1 -1
- package/dist/src/a2a/__tests__/server.test.js +20 -0
- package/dist/src/a2a/__tests__/server.test.js.map +1 -1
- package/dist/src/a2a/async-lock.d.ts +22 -0
- package/dist/src/a2a/async-lock.d.ts.map +1 -0
- package/dist/src/a2a/async-lock.js +38 -0
- package/dist/src/a2a/async-lock.js.map +1 -0
- package/dist/src/a2a/executor.d.ts +59 -24
- package/dist/src/a2a/executor.d.ts.map +1 -1
- package/dist/src/a2a/executor.js +209 -32
- package/dist/src/a2a/executor.js.map +1 -1
- package/dist/src/a2a/index.d.ts +1 -1
- package/dist/src/a2a/index.d.ts.map +1 -1
- package/dist/src/a2a/index.js +1 -1
- package/dist/src/a2a/index.js.map +1 -1
- package/dist/src/a2a/server.d.ts +18 -2
- package/dist/src/a2a/server.d.ts.map +1 -1
- package/dist/src/a2a/server.js +13 -2
- package/dist/src/a2a/server.js.map +1 -1
- package/dist/src/agent/__tests__/agent.context-manager.test.d.ts +2 -0
- package/dist/src/agent/__tests__/agent.context-manager.test.d.ts.map +1 -0
- package/dist/src/agent/__tests__/agent.context-manager.test.js +107 -0
- package/dist/src/agent/__tests__/agent.context-manager.test.js.map +1 -0
- package/dist/src/agent/__tests__/agent.tracer.test.node.js +14 -0
- package/dist/src/agent/__tests__/agent.tracer.test.node.js.map +1 -1
- package/dist/src/agent/agent.d.ts +132 -2
- package/dist/src/agent/agent.d.ts.map +1 -1
- package/dist/src/agent/agent.js +478 -188
- package/dist/src/agent/agent.js.map +1 -1
- package/dist/src/conversation-manager/__tests__/pin.test.d.ts +2 -0
- package/dist/src/conversation-manager/__tests__/pin.test.d.ts.map +1 -0
- package/dist/src/conversation-manager/__tests__/pin.test.js +119 -0
- package/dist/src/conversation-manager/__tests__/pin.test.js.map +1 -0
- package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js +49 -0
- package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js.map +1 -1
- package/dist/src/conversation-manager/__tests__/summarizing-conversation-manager.test.js +58 -0
- package/dist/src/conversation-manager/__tests__/summarizing-conversation-manager.test.js.map +1 -1
- package/dist/src/conversation-manager/pin-message.d.ts +45 -0
- package/dist/src/conversation-manager/pin-message.d.ts.map +1 -0
- package/dist/src/conversation-manager/pin-message.js +106 -0
- package/dist/src/conversation-manager/pin-message.js.map +1 -0
- package/dist/src/conversation-manager/sliding-window-conversation-manager.d.ts +7 -0
- package/dist/src/conversation-manager/sliding-window-conversation-manager.d.ts.map +1 -1
- package/dist/src/conversation-manager/sliding-window-conversation-manager.js +27 -4
- package/dist/src/conversation-manager/sliding-window-conversation-manager.js.map +1 -1
- package/dist/src/conversation-manager/summarizing-conversation-manager.d.ts +7 -0
- package/dist/src/conversation-manager/summarizing-conversation-manager.d.ts.map +1 -1
- package/dist/src/conversation-manager/summarizing-conversation-manager.js +18 -4
- package/dist/src/conversation-manager/summarizing-conversation-manager.js.map +1 -1
- package/dist/src/default-slot.d.ts +6 -0
- package/dist/src/default-slot.d.ts.map +1 -0
- package/dist/src/default-slot.js +18 -0
- package/dist/src/default-slot.js.map +1 -0
- package/dist/src/errors.d.ts +8 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +11 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/index.d.ts +8 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.node.d.ts +2 -0
- package/dist/src/index.node.d.ts.map +1 -0
- package/dist/src/index.node.js +9 -0
- package/dist/src/index.node.js.map +1 -0
- package/dist/src/interrupt.d.ts +5 -1
- package/dist/src/interrupt.d.ts.map +1 -1
- package/dist/src/interrupt.js +6 -0
- package/dist/src/interrupt.js.map +1 -1
- package/dist/src/memory/__tests__/memory-manager.test.d.ts +2 -0
- package/dist/src/memory/__tests__/memory-manager.test.d.ts.map +1 -0
- package/dist/src/memory/__tests__/memory-manager.test.js +493 -0
- package/dist/src/memory/__tests__/memory-manager.test.js.map +1 -0
- package/dist/src/memory/extraction/__tests__/extraction.test.d.ts +2 -0
- package/dist/src/memory/extraction/__tests__/extraction.test.d.ts.map +1 -0
- package/dist/src/memory/extraction/__tests__/extraction.test.js +637 -0
- package/dist/src/memory/extraction/__tests__/extraction.test.js.map +1 -0
- package/dist/src/memory/extraction/__tests__/model-extractor.test.d.ts +2 -0
- package/dist/src/memory/extraction/__tests__/model-extractor.test.d.ts.map +1 -0
- package/dist/src/memory/extraction/__tests__/model-extractor.test.js +68 -0
- package/dist/src/memory/extraction/__tests__/model-extractor.test.js.map +1 -0
- package/dist/src/memory/extraction/__tests__/resolve-extraction-config.test.d.ts +2 -0
- package/dist/src/memory/extraction/__tests__/resolve-extraction-config.test.d.ts.map +1 -0
- package/dist/src/memory/extraction/__tests__/resolve-extraction-config.test.js +81 -0
- package/dist/src/memory/extraction/__tests__/resolve-extraction-config.test.js.map +1 -0
- package/dist/src/memory/extraction/coordinator.d.ts +128 -0
- package/dist/src/memory/extraction/coordinator.d.ts.map +1 -0
- package/dist/src/memory/extraction/coordinator.js +245 -0
- package/dist/src/memory/extraction/coordinator.js.map +1 -0
- package/dist/src/memory/extraction/model-extractor.d.ts +32 -0
- package/dist/src/memory/extraction/model-extractor.d.ts.map +1 -0
- package/dist/src/memory/extraction/model-extractor.js +118 -0
- package/dist/src/memory/extraction/model-extractor.js.map +1 -0
- package/dist/src/memory/extraction/resolve-extraction-config.d.ts +46 -0
- package/dist/src/memory/extraction/resolve-extraction-config.d.ts.map +1 -0
- package/dist/src/memory/extraction/resolve-extraction-config.js +59 -0
- package/dist/src/memory/extraction/resolve-extraction-config.js.map +1 -0
- package/dist/src/memory/extraction/triggers.d.ts +41 -0
- package/dist/src/memory/extraction/triggers.d.ts.map +1 -0
- package/dist/src/memory/extraction/triggers.js +59 -0
- package/dist/src/memory/extraction/triggers.js.map +1 -0
- package/dist/src/memory/extraction/types.d.ts +133 -0
- package/dist/src/memory/extraction/types.d.ts.map +1 -0
- package/dist/src/memory/extraction/types.js +19 -0
- package/dist/src/memory/extraction/types.js.map +1 -0
- package/dist/src/memory/index.d.ts +9 -0
- package/dist/src/memory/index.d.ts.map +1 -0
- package/dist/src/memory/index.js +5 -0
- package/dist/src/memory/index.js.map +1 -0
- package/dist/src/memory/memory-manager.d.ts +131 -0
- package/dist/src/memory/memory-manager.d.ts.map +1 -0
- package/dist/src/memory/memory-manager.js +404 -0
- package/dist/src/memory/memory-manager.js.map +1 -0
- package/dist/src/memory/types.d.ts +213 -0
- package/dist/src/memory/types.d.ts.map +1 -0
- package/dist/src/memory/types.js +2 -0
- package/dist/src/memory/types.js.map +1 -0
- package/dist/src/middleware/__tests__/agent-middleware.test.d.ts +2 -0
- package/dist/src/middleware/__tests__/agent-middleware.test.d.ts.map +1 -0
- package/dist/src/middleware/__tests__/agent-middleware.test.js +1207 -0
- package/dist/src/middleware/__tests__/agent-middleware.test.js.map +1 -0
- package/dist/src/middleware/__tests__/custom-stages.test.d.ts +2 -0
- package/dist/src/middleware/__tests__/custom-stages.test.d.ts.map +1 -0
- package/dist/src/middleware/__tests__/custom-stages.test.js +97 -0
- package/dist/src/middleware/__tests__/custom-stages.test.js.map +1 -0
- package/dist/src/middleware/__tests__/middleware-interrupts.test.d.ts +2 -0
- package/dist/src/middleware/__tests__/middleware-interrupts.test.d.ts.map +1 -0
- package/dist/src/middleware/__tests__/middleware-interrupts.test.js +267 -0
- package/dist/src/middleware/__tests__/middleware-interrupts.test.js.map +1 -0
- package/dist/src/middleware/__tests__/registry.test.d.ts +2 -0
- package/dist/src/middleware/__tests__/registry.test.d.ts.map +1 -0
- package/dist/src/middleware/__tests__/registry.test.js +525 -0
- package/dist/src/middleware/__tests__/registry.test.js.map +1 -0
- package/dist/src/middleware/index.d.ts +5 -0
- package/dist/src/middleware/index.d.ts.map +1 -0
- package/dist/src/middleware/index.js +3 -0
- package/dist/src/middleware/index.js.map +1 -0
- package/dist/src/middleware/registry.d.ts +58 -0
- package/dist/src/middleware/registry.d.ts.map +1 -0
- package/dist/src/middleware/registry.js +107 -0
- package/dist/src/middleware/registry.js.map +1 -0
- package/dist/src/middleware/stages.d.ts +138 -0
- package/dist/src/middleware/stages.d.ts.map +1 -0
- package/dist/src/middleware/stages.js +31 -0
- package/dist/src/middleware/stages.js.map +1 -0
- package/dist/src/middleware/types.d.ts +88 -0
- package/dist/src/middleware/types.d.ts.map +1 -0
- package/dist/src/middleware/types.js +2 -0
- package/dist/src/middleware/types.js.map +1 -0
- package/dist/src/models/__tests__/anthropic.test.js +16 -1
- package/dist/src/models/__tests__/anthropic.test.js.map +1 -1
- package/dist/src/models/__tests__/bedrock.test.js +39 -0
- package/dist/src/models/__tests__/bedrock.test.js.map +1 -1
- package/dist/src/models/__tests__/model.test.js +46 -3
- package/dist/src/models/__tests__/model.test.js.map +1 -1
- package/dist/src/models/anthropic.js +2 -2
- package/dist/src/models/anthropic.js.map +1 -1
- package/dist/src/models/bedrock.d.ts.map +1 -1
- package/dist/src/models/bedrock.js +12 -5
- package/dist/src/models/bedrock.js.map +1 -1
- package/dist/src/models/defaults.d.ts.map +1 -1
- package/dist/src/models/defaults.js +2 -0
- package/dist/src/models/defaults.js.map +1 -1
- package/dist/src/models/model.d.ts.map +1 -1
- package/dist/src/models/model.js +7 -3
- package/dist/src/models/model.js.map +1 -1
- package/dist/src/models/openai/__tests__/responses.test.js +8 -14
- package/dist/src/models/openai/__tests__/responses.test.js.map +1 -1
- package/dist/src/sandbox/__tests__/default.test.browser.d.ts +2 -0
- package/dist/src/sandbox/__tests__/default.test.browser.d.ts.map +1 -0
- package/dist/src/sandbox/__tests__/default.test.browser.js +11 -0
- package/dist/src/sandbox/__tests__/default.test.browser.js.map +1 -0
- package/dist/src/sandbox/__tests__/default.test.node.d.ts +2 -0
- package/dist/src/sandbox/__tests__/default.test.node.d.ts.map +1 -0
- package/dist/src/sandbox/__tests__/default.test.node.js +23 -0
- package/dist/src/sandbox/__tests__/default.test.node.js.map +1 -0
- package/dist/src/sandbox/__tests__/docker.test.node.d.ts +2 -0
- package/dist/src/sandbox/__tests__/docker.test.node.d.ts.map +1 -0
- package/dist/src/sandbox/__tests__/docker.test.node.js +89 -0
- package/dist/src/sandbox/__tests__/docker.test.node.js.map +1 -0
- package/dist/src/sandbox/__tests__/errors.test.node.d.ts +2 -0
- package/dist/src/sandbox/__tests__/errors.test.node.d.ts.map +1 -0
- package/dist/src/sandbox/__tests__/errors.test.node.js +33 -0
- package/dist/src/sandbox/__tests__/errors.test.node.js.map +1 -0
- package/dist/src/sandbox/__tests__/not-a-sandbox-local-environment.test.node.d.ts +2 -0
- package/dist/src/sandbox/__tests__/not-a-sandbox-local-environment.test.node.d.ts.map +1 -0
- package/dist/src/sandbox/__tests__/not-a-sandbox-local-environment.test.node.js +124 -0
- package/dist/src/sandbox/__tests__/not-a-sandbox-local-environment.test.node.js.map +1 -0
- package/dist/src/sandbox/__tests__/posix-shell.test.node.js +50 -4
- package/dist/src/sandbox/__tests__/posix-shell.test.node.js.map +1 -1
- package/dist/src/sandbox/__tests__/ssh.test.node.d.ts +2 -0
- package/dist/src/sandbox/__tests__/ssh.test.node.d.ts.map +1 -0
- package/dist/src/sandbox/__tests__/ssh.test.node.js +262 -0
- package/dist/src/sandbox/__tests__/ssh.test.node.js.map +1 -0
- package/dist/src/sandbox/base.d.ts +22 -4
- package/dist/src/sandbox/base.d.ts.map +1 -1
- package/dist/src/sandbox/base.js +15 -2
- package/dist/src/sandbox/base.js.map +1 -1
- package/dist/src/sandbox/constants.d.ts +18 -0
- package/dist/src/sandbox/constants.d.ts.map +1 -1
- package/dist/src/sandbox/constants.js +20 -0
- package/dist/src/sandbox/constants.js.map +1 -1
- package/dist/src/sandbox/default.d.ts +3 -0
- package/dist/src/sandbox/default.d.ts.map +1 -0
- package/dist/src/sandbox/default.js +3 -0
- package/dist/src/sandbox/default.js.map +1 -0
- package/dist/src/sandbox/docker.d.ts +38 -0
- package/dist/src/sandbox/docker.d.ts.map +1 -0
- package/dist/src/sandbox/docker.js +59 -0
- package/dist/src/sandbox/docker.js.map +1 -0
- package/dist/src/sandbox/errors.d.ts +26 -0
- package/dist/src/sandbox/errors.d.ts.map +1 -0
- package/dist/src/sandbox/errors.js +35 -0
- package/dist/src/sandbox/errors.js.map +1 -0
- package/dist/src/sandbox/index.d.ts +5 -0
- package/dist/src/sandbox/index.d.ts.map +1 -0
- package/dist/src/sandbox/index.js +4 -0
- package/dist/src/sandbox/index.js.map +1 -0
- package/dist/src/sandbox/not-a-sandbox-local-environment.d.ts +16 -0
- package/dist/src/sandbox/not-a-sandbox-local-environment.d.ts.map +1 -0
- package/dist/src/sandbox/not-a-sandbox-local-environment.js +83 -0
- package/dist/src/sandbox/not-a-sandbox-local-environment.js.map +1 -0
- package/dist/src/sandbox/posix-shell.d.ts +21 -0
- package/dist/src/sandbox/posix-shell.d.ts.map +1 -1
- package/dist/src/sandbox/posix-shell.js +41 -3
- package/dist/src/sandbox/posix-shell.js.map +1 -1
- package/dist/src/sandbox/ssh.d.ts +56 -0
- package/dist/src/sandbox/ssh.d.ts.map +1 -0
- package/dist/src/sandbox/ssh.js +119 -0
- package/dist/src/sandbox/ssh.js.map +1 -0
- package/dist/src/sandbox/stream-process.d.ts.map +1 -1
- package/dist/src/sandbox/stream-process.js +3 -2
- package/dist/src/sandbox/stream-process.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/types/agent.d.ts +21 -0
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/agent.js.map +1 -1
- package/dist/src/types/messages.d.ts +1 -1
- package/dist/src/types/messages.d.ts.map +1 -1
- package/dist/src/types/messages.js.map +1 -1
- package/dist/src/vended-memory-stores/bedrock-knowledge-base/__tests__/bedrock-knowledge-base-store.test.d.ts +2 -0
- package/dist/src/vended-memory-stores/bedrock-knowledge-base/__tests__/bedrock-knowledge-base-store.test.d.ts.map +1 -0
- package/dist/src/vended-memory-stores/bedrock-knowledge-base/__tests__/bedrock-knowledge-base-store.test.js +611 -0
- package/dist/src/vended-memory-stores/bedrock-knowledge-base/__tests__/bedrock-knowledge-base-store.test.js.map +1 -0
- package/dist/src/vended-memory-stores/bedrock-knowledge-base/index.d.ts +2 -0
- package/dist/src/vended-memory-stores/bedrock-knowledge-base/index.d.ts.map +1 -0
- package/dist/src/vended-memory-stores/bedrock-knowledge-base/index.js +2 -0
- package/dist/src/vended-memory-stores/bedrock-knowledge-base/index.js.map +1 -0
- package/dist/src/vended-memory-stores/bedrock-knowledge-base/store.d.ts +230 -0
- package/dist/src/vended-memory-stores/bedrock-knowledge-base/store.d.ts.map +1 -0
- package/dist/src/vended-memory-stores/bedrock-knowledge-base/store.js +370 -0
- package/dist/src/vended-memory-stores/bedrock-knowledge-base/store.js.map +1 -0
- package/dist/src/vended-plugins/context-offloader/__tests__/file-storage-sandbox.test.node.d.ts +2 -0
- package/dist/src/vended-plugins/context-offloader/__tests__/file-storage-sandbox.test.node.d.ts.map +1 -0
- package/dist/src/vended-plugins/context-offloader/__tests__/file-storage-sandbox.test.node.js +68 -0
- package/dist/src/vended-plugins/context-offloader/__tests__/file-storage-sandbox.test.node.js.map +1 -0
- package/dist/src/vended-plugins/context-offloader/__tests__/plugin.test.node.d.ts +2 -0
- package/dist/src/vended-plugins/context-offloader/__tests__/plugin.test.node.d.ts.map +1 -0
- package/dist/src/vended-plugins/context-offloader/__tests__/plugin.test.node.js +93 -0
- package/dist/src/vended-plugins/context-offloader/__tests__/plugin.test.node.js.map +1 -0
- package/dist/src/vended-plugins/context-offloader/index.d.ts +1 -1
- package/dist/src/vended-plugins/context-offloader/index.d.ts.map +1 -1
- package/dist/src/vended-plugins/context-offloader/plugin.d.ts +4 -1
- package/dist/src/vended-plugins/context-offloader/plugin.d.ts.map +1 -1
- package/dist/src/vended-plugins/context-offloader/plugin.js +29 -7
- package/dist/src/vended-plugins/context-offloader/plugin.js.map +1 -1
- package/dist/src/vended-plugins/context-offloader/search.d.ts.map +1 -1
- package/dist/src/vended-plugins/context-offloader/search.js +3 -5
- package/dist/src/vended-plugins/context-offloader/search.js.map +1 -1
- package/dist/src/vended-plugins/context-offloader/storage.d.ts +29 -5
- package/dist/src/vended-plugins/context-offloader/storage.d.ts.map +1 -1
- package/dist/src/vended-plugins/context-offloader/storage.js +75 -11
- package/dist/src/vended-plugins/context-offloader/storage.js.map +1 -1
- package/dist/src/vended-plugins/goal/__tests__/plugin.test.d.ts +2 -0
- package/dist/src/vended-plugins/goal/__tests__/plugin.test.d.ts.map +1 -0
- package/dist/src/vended-plugins/goal/__tests__/plugin.test.js +736 -0
- package/dist/src/vended-plugins/goal/__tests__/plugin.test.js.map +1 -0
- package/dist/src/vended-plugins/goal/index.d.ts +21 -0
- package/dist/src/vended-plugins/goal/index.d.ts.map +1 -0
- package/dist/src/vended-plugins/goal/index.js +20 -0
- package/dist/src/vended-plugins/goal/index.js.map +1 -0
- package/dist/src/vended-plugins/goal/judge.d.ts +41 -0
- package/dist/src/vended-plugins/goal/judge.d.ts.map +1 -0
- package/dist/src/vended-plugins/goal/judge.js +92 -0
- package/dist/src/vended-plugins/goal/judge.js.map +1 -0
- package/dist/src/vended-plugins/goal/plugin.d.ts +214 -0
- package/dist/src/vended-plugins/goal/plugin.d.ts.map +1 -0
- package/dist/src/vended-plugins/goal/plugin.js +287 -0
- package/dist/src/vended-plugins/goal/plugin.js.map +1 -0
- package/dist/src/vended-plugins/index.d.ts +2 -1
- package/dist/src/vended-plugins/index.d.ts.map +1 -1
- package/dist/src/vended-plugins/index.js +2 -1
- package/dist/src/vended-plugins/index.js.map +1 -1
- package/dist/src/vended-plugins/skills/__tests__/agent-skills.test.node.js +17 -7
- package/dist/src/vended-plugins/skills/__tests__/agent-skills.test.node.js.map +1 -1
- package/dist/src/vended-plugins/skills/agent-skills.d.ts +21 -7
- package/dist/src/vended-plugins/skills/agent-skills.d.ts.map +1 -1
- package/dist/src/vended-plugins/skills/agent-skills.js +144 -77
- package/dist/src/vended-plugins/skills/agent-skills.js.map +1 -1
- package/dist/src/vended-tools/bash/__tests__/bash.test.node.js +44 -4
- package/dist/src/vended-tools/bash/__tests__/bash.test.node.js.map +1 -1
- package/dist/src/vended-tools/bash/bash.d.ts +3 -24
- package/dist/src/vended-tools/bash/bash.d.ts.map +1 -1
- package/dist/src/vended-tools/bash/bash.js +9 -9
- package/dist/src/vended-tools/bash/bash.js.map +1 -1
- package/dist/src/vended-tools/bash/index.d.ts +3 -1
- package/dist/src/vended-tools/bash/index.d.ts.map +1 -1
- package/dist/src/vended-tools/bash/index.js +2 -1
- package/dist/src/vended-tools/bash/index.js.map +1 -1
- package/dist/src/vended-tools/bash/make-bash.d.ts +22 -0
- package/dist/src/vended-tools/bash/make-bash.d.ts.map +1 -0
- package/dist/src/vended-tools/bash/make-bash.js +40 -0
- package/dist/src/vended-tools/bash/make-bash.js.map +1 -0
- package/dist/src/vended-tools/bash/types.d.ts +1 -0
- package/dist/src/vended-tools/bash/types.d.ts.map +1 -1
- package/dist/src/vended-tools/bash/types.js +2 -0
- package/dist/src/vended-tools/bash/types.js.map +1 -1
- package/dist/src/vended-tools/file-editor/__tests__/file-editor.test.node.js +83 -1
- package/dist/src/vended-tools/file-editor/__tests__/file-editor.test.node.js.map +1 -1
- package/dist/src/vended-tools/file-editor/file-editor.d.ts +19 -10
- package/dist/src/vended-tools/file-editor/file-editor.d.ts.map +1 -1
- package/dist/src/vended-tools/file-editor/file-editor.js +188 -218
- package/dist/src/vended-tools/file-editor/file-editor.js.map +1 -1
- package/dist/src/vended-tools/file-editor/index.d.ts +2 -1
- package/dist/src/vended-tools/file-editor/index.d.ts.map +1 -1
- package/dist/src/vended-tools/file-editor/index.js +1 -1
- package/dist/src/vended-tools/file-editor/index.js.map +1 -1
- package/package.json +41 -6
- package/dist/src/utils/shell-quote.d.ts +0 -12
- package/dist/src/utils/shell-quote.d.ts.map +0 -1
- package/dist/src/utils/shell-quote.js +0 -14
- package/dist/src/utils/shell-quote.js.map +0 -1
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* code execution, and file I/O) and convenience wrappers for common patterns.
|
|
7
7
|
*/
|
|
8
8
|
import type { ExecutionResult, FileInfo, StreamChunk } from './types.js';
|
|
9
|
+
import type { Tool } from '../tools/tool.js';
|
|
9
10
|
/**
|
|
10
11
|
* Options for command and code execution.
|
|
11
12
|
*/
|
|
@@ -16,6 +17,12 @@ export interface ExecuteOptions {
|
|
|
16
17
|
cwd?: string | undefined;
|
|
17
18
|
/** Abort signal to cancel execution. The process is killed when the signal fires. */
|
|
18
19
|
signal?: AbortSignal | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Environment variables to set for this command. Built-in sandboxes always apply these,
|
|
22
|
+
* though the mechanism differs (Docker `-e` flags, SSH `env` prefix); custom `Sandbox`
|
|
23
|
+
* implementations must handle env explicitly or it has no effect.
|
|
24
|
+
*/
|
|
25
|
+
env?: Record<string, string> | undefined;
|
|
19
26
|
}
|
|
20
27
|
/**
|
|
21
28
|
* Abstract execution environment.
|
|
@@ -38,7 +45,7 @@ export declare abstract class Sandbox {
|
|
|
38
45
|
* exit code and complete output.
|
|
39
46
|
*
|
|
40
47
|
* @param command - The shell command to execute.
|
|
41
|
-
* @param options - Execution options
|
|
48
|
+
* @param options - Execution options.
|
|
42
49
|
* @returns Async iterable yielding StreamChunks followed by a final ExecutionResult.
|
|
43
50
|
*/
|
|
44
51
|
abstract executeStreaming(command: string, options?: ExecuteOptions): AsyncIterable<StreamChunk | ExecutionResult>;
|
|
@@ -47,7 +54,7 @@ export declare abstract class Sandbox {
|
|
|
47
54
|
*
|
|
48
55
|
* @param code - The source code to execute.
|
|
49
56
|
* @param language - The interpreter to use (e.g., `"python3"`, `"node"`).
|
|
50
|
-
* @param options - Execution options
|
|
57
|
+
* @param options - Execution options.
|
|
51
58
|
* @returns Async iterable yielding StreamChunks followed by a final ExecutionResult.
|
|
52
59
|
*/
|
|
53
60
|
abstract executeCodeStreaming(code: string, language: string, options?: ExecuteOptions): AsyncIterable<StreamChunk | ExecutionResult>;
|
|
@@ -91,6 +98,17 @@ export declare abstract class Sandbox {
|
|
|
91
98
|
* @throws Error if the directory does not exist.
|
|
92
99
|
*/
|
|
93
100
|
abstract listFiles(path: string): Promise<FileInfo[]>;
|
|
101
|
+
/**
|
|
102
|
+
* Prefix applied to tool names when registered on an agent (e.g. `'sandbox'` produces
|
|
103
|
+
* `sandbox_bash`). Set to `undefined` to disable prefixing. Defaults to `'sandbox'`.
|
|
104
|
+
*/
|
|
105
|
+
toolPrefix: string | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Tools this sandbox vends to an agent, registered during `Agent.initialize()`.
|
|
108
|
+
* A tool is skipped if the user already registered one with the same name.
|
|
109
|
+
* Override to provide them.
|
|
110
|
+
*/
|
|
111
|
+
getTools(): Tool[];
|
|
94
112
|
/**
|
|
95
113
|
* Execute a shell command and return the result.
|
|
96
114
|
*
|
|
@@ -98,7 +116,7 @@ export declare abstract class Sandbox {
|
|
|
98
116
|
* Use `executeStreaming` when you need to process output as it arrives.
|
|
99
117
|
*
|
|
100
118
|
* @param command - The shell command to execute.
|
|
101
|
-
* @param options - Execution options
|
|
119
|
+
* @param options - Execution options.
|
|
102
120
|
* @returns The execution result with exit code and output.
|
|
103
121
|
*/
|
|
104
122
|
execute(command: string, options?: ExecuteOptions): Promise<ExecutionResult>;
|
|
@@ -110,7 +128,7 @@ export declare abstract class Sandbox {
|
|
|
110
128
|
*
|
|
111
129
|
* @param code - The source code to execute.
|
|
112
130
|
* @param language - The interpreter to use.
|
|
113
|
-
* @param options - Execution options
|
|
131
|
+
* @param options - Execution options.
|
|
114
132
|
* @returns The execution result with exit code and output.
|
|
115
133
|
*/
|
|
116
134
|
executeCode(code: string, language: string, options?: ExecuteOptions): Promise<ExecutionResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/sandbox/base.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/sandbox/base.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAE5C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,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CAAC;IASlF;;;;;;;;;;OAUG;IACG,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IASrG;;;;;;;;OAQG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI7C;;;;;;;;OAQG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9D"}
|
package/dist/src/sandbox/base.js
CHANGED
|
@@ -18,6 +18,19 @@
|
|
|
18
18
|
* the stream and return the final result.
|
|
19
19
|
*/
|
|
20
20
|
export class Sandbox {
|
|
21
|
+
/**
|
|
22
|
+
* Prefix applied to tool names when registered on an agent (e.g. `'sandbox'` produces
|
|
23
|
+
* `sandbox_bash`). Set to `undefined` to disable prefixing. Defaults to `'sandbox'`.
|
|
24
|
+
*/
|
|
25
|
+
toolPrefix = 'sandbox';
|
|
26
|
+
/**
|
|
27
|
+
* Tools this sandbox vends to an agent, registered during `Agent.initialize()`.
|
|
28
|
+
* A tool is skipped if the user already registered one with the same name.
|
|
29
|
+
* Override to provide them.
|
|
30
|
+
*/
|
|
31
|
+
getTools() {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
21
34
|
// ---- Non-streaming convenience methods ----
|
|
22
35
|
/**
|
|
23
36
|
* Execute a shell command and return the result.
|
|
@@ -26,7 +39,7 @@ export class Sandbox {
|
|
|
26
39
|
* Use `executeStreaming` when you need to process output as it arrives.
|
|
27
40
|
*
|
|
28
41
|
* @param command - The shell command to execute.
|
|
29
|
-
* @param options - Execution options
|
|
42
|
+
* @param options - Execution options.
|
|
30
43
|
* @returns The execution result with exit code and output.
|
|
31
44
|
*/
|
|
32
45
|
async execute(command, options) {
|
|
@@ -45,7 +58,7 @@ export class Sandbox {
|
|
|
45
58
|
*
|
|
46
59
|
* @param code - The source code to execute.
|
|
47
60
|
* @param language - The interpreter to use.
|
|
48
|
-
* @param options - Execution options
|
|
61
|
+
* @param options - Execution options.
|
|
49
62
|
* @returns The execution result with exit code and output.
|
|
50
63
|
*/
|
|
51
64
|
async executeCode(code, language, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/sandbox/base.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/sandbox/base.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuBH;;;;;;;;;;;GAWG;AACH,MAAM,OAAgB,OAAO;IAwE3B;;;OAGG;IACH,UAAU,GAAuB,SAAS,CAAA;IAE1C;;;;OAIG;IACH,QAAQ;QACN,OAAO,EAAE,CAAA;IACX,CAAC;IAED,8CAA8C;IAE9C;;;;;;;;;OASG;IACH,KAAK,CAAC,OAAO,CAAC,OAAe,EAAE,OAAwB;QACrD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;YAClE,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;gBACrC,OAAO,KAAK,CAAA;YACd,CAAC;QACH,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAA;IACxE,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,WAAW,CAAC,IAAY,EAAE,QAAgB,EAAE,OAAwB;QACxE,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC;YAC7E,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;gBACrC,OAAO,KAAK,CAAA;YACd,CAAC;QACH,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAA;IAC5E,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,QAAQ,CAAC,IAAY;QACzB,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;IAC5D,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,OAAe;QAC3C,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;IAC/D,CAAC;CACF"}
|
|
@@ -4,4 +4,22 @@
|
|
|
4
4
|
* Rejects path separators, spaces, and shell metacharacters to prevent injection.
|
|
5
5
|
*/
|
|
6
6
|
export declare const LANGUAGE_PATTERN: RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* Regex pattern for validating environment variable names: a leading letter or
|
|
9
|
+
* underscore, followed by letters, digits, or underscores (valid POSIX names).
|
|
10
|
+
* Names outside this set are rejected to prevent shell-syntax injection where a
|
|
11
|
+
* key is interpolated into a command, and to fail with a clear error otherwise.
|
|
12
|
+
*/
|
|
13
|
+
export declare const ENV_KEY_PATTERN: RegExp;
|
|
14
|
+
/**
|
|
15
|
+
* Shell-escape a string for safe inclusion in a shell command.
|
|
16
|
+
*
|
|
17
|
+
* Wraps the value in single quotes and escapes any embedded single quotes
|
|
18
|
+
* using the '\'' pattern. Single quotes disable all shell expansion
|
|
19
|
+
* (variables, backticks, globbing), making this safe against injection.
|
|
20
|
+
*
|
|
21
|
+
* @param value - The string to escape.
|
|
22
|
+
* @returns The shell-escaped string wrapped in single quotes.
|
|
23
|
+
*/
|
|
24
|
+
export declare function shellQuote(value: string): string;
|
|
7
25
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/sandbox/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAsB,CAAA"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/sandbox/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAsB,CAAA;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAA6B,CAAA;AAEzD;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD"}
|
|
@@ -4,4 +4,24 @@
|
|
|
4
4
|
* Rejects path separators, spaces, and shell metacharacters to prevent injection.
|
|
5
5
|
*/
|
|
6
6
|
export const LANGUAGE_PATTERN = /^[a-zA-Z0-9._-]+$/;
|
|
7
|
+
/**
|
|
8
|
+
* Regex pattern for validating environment variable names: a leading letter or
|
|
9
|
+
* underscore, followed by letters, digits, or underscores (valid POSIX names).
|
|
10
|
+
* Names outside this set are rejected to prevent shell-syntax injection where a
|
|
11
|
+
* key is interpolated into a command, and to fail with a clear error otherwise.
|
|
12
|
+
*/
|
|
13
|
+
export const ENV_KEY_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
14
|
+
/**
|
|
15
|
+
* Shell-escape a string for safe inclusion in a shell command.
|
|
16
|
+
*
|
|
17
|
+
* Wraps the value in single quotes and escapes any embedded single quotes
|
|
18
|
+
* using the '\'' pattern. Single quotes disable all shell expansion
|
|
19
|
+
* (variables, backticks, globbing), making this safe against injection.
|
|
20
|
+
*
|
|
21
|
+
* @param value - The string to escape.
|
|
22
|
+
* @returns The shell-escaped string wrapped in single quotes.
|
|
23
|
+
*/
|
|
24
|
+
export function shellQuote(value) {
|
|
25
|
+
return "'" + value.replace(/'/g, "'\\''") + "'";
|
|
26
|
+
}
|
|
7
27
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/sandbox/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/sandbox/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,mBAAmB,CAAA;AAEnD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,0BAA0B,CAAA;AAEzD;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,GAAG,CAAA;AACjD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../../src/sandbox/default.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGxC,eAAO,MAAM,cAAc,mDAE1B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default.js","sourceRoot":"","sources":["../../../src/sandbox/default.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAEtD,MAAM,CAAC,MAAM,cAAc,GAAG,iBAAiB,CAC7C,mGAAmG,CACpG,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Docker sandbox — executes commands in a Docker container via `docker exec`.
|
|
3
|
+
*/
|
|
4
|
+
import type { ExecuteOptions } from './base.js';
|
|
5
|
+
import { PosixShellSandbox } from './posix-shell.js';
|
|
6
|
+
import type { ExecutionResult, StreamChunk } from './types.js';
|
|
7
|
+
import type { Tool } from '../tools/tool.js';
|
|
8
|
+
/**
|
|
9
|
+
* Options for constructing a {@link DockerSandbox}.
|
|
10
|
+
*/
|
|
11
|
+
export interface DockerSandboxOptions {
|
|
12
|
+
/** ID or name of a running Docker container. */
|
|
13
|
+
container: string;
|
|
14
|
+
/**
|
|
15
|
+
* Working directory for executed commands. If omitted, no `-w` flag is set and
|
|
16
|
+
* commands run in the container's configured working directory.
|
|
17
|
+
*
|
|
18
|
+
* Set this to run elsewhere; the path must exist and be writable by the effective {@link user}.
|
|
19
|
+
*/
|
|
20
|
+
workingDir?: string;
|
|
21
|
+
/**
|
|
22
|
+
* User to run commands as, in `"uid"`, `"uid:gid"`, or `"name"` form. If omitted,
|
|
23
|
+
* no `--user` flag is set and commands run as the container's configured user.
|
|
24
|
+
*
|
|
25
|
+
* Set this to override the container's identity, e.g. `"root"` or `"1000:1000"`.
|
|
26
|
+
*/
|
|
27
|
+
user?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Execute commands in a Docker container via `docker exec`. */
|
|
30
|
+
export declare class DockerSandbox extends PosixShellSandbox {
|
|
31
|
+
readonly container: string;
|
|
32
|
+
readonly workingDir: string | undefined;
|
|
33
|
+
private readonly _user;
|
|
34
|
+
constructor(options: DockerSandboxOptions);
|
|
35
|
+
executeStreaming(command: string, options?: ExecuteOptions): AsyncGenerator<StreamChunk | ExecutionResult, void, undefined>;
|
|
36
|
+
getTools(): Tool[];
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=docker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docker.d.ts","sourceRoot":"","sources":["../../../src/sandbox/docker.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAmB,MAAM,kBAAkB,CAAA;AAErE,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAI5C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAA;IACjB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,gEAAgE;AAChE,qBAAa,aAAc,SAAQ,iBAAiB;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IACvC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoB;gBAE9B,OAAO,EAAE,oBAAoB;IAOlC,gBAAgB,CACrB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,cAAc,GACvB,cAAc,CAAC,WAAW,GAAG,eAAe,EAAE,IAAI,EAAE,SAAS,CAAC;IAgCxD,QAAQ,IAAI,IAAI,EAAE;CAW5B"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Docker sandbox — executes commands in a Docker container via `docker exec`.
|
|
3
|
+
*/
|
|
4
|
+
import { PosixShellSandbox, validateEnvKeys } from './posix-shell.js';
|
|
5
|
+
import { streamProcess } from './stream-process.js';
|
|
6
|
+
import { makeFileEditor, DEFAULT_FILE_EDITOR_DESCRIPTION } from '../vended-tools/file-editor/index.js';
|
|
7
|
+
import { makeBash, SANDBOX_BASH_DESCRIPTION } from '../vended-tools/bash/index.js';
|
|
8
|
+
/** Execute commands in a Docker container via `docker exec`. */
|
|
9
|
+
export class DockerSandbox extends PosixShellSandbox {
|
|
10
|
+
container;
|
|
11
|
+
workingDir;
|
|
12
|
+
_user;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super();
|
|
15
|
+
this.container = options.container;
|
|
16
|
+
this.workingDir = options.workingDir;
|
|
17
|
+
this._user = options.user;
|
|
18
|
+
}
|
|
19
|
+
async *executeStreaming(command, options) {
|
|
20
|
+
const args = ['exec'];
|
|
21
|
+
// Unset user/cwd defer to the container's own configuration.
|
|
22
|
+
if (this._user !== undefined)
|
|
23
|
+
args.push('--user', this._user);
|
|
24
|
+
const cwd = options?.cwd ?? this.workingDir;
|
|
25
|
+
if (cwd !== undefined)
|
|
26
|
+
args.push('-w', cwd);
|
|
27
|
+
if (options?.env) {
|
|
28
|
+
validateEnvKeys(options.env);
|
|
29
|
+
for (const [key, val] of Object.entries(options.env)) {
|
|
30
|
+
// Values are passed as process argv (not through a shell), so no escaping is
|
|
31
|
+
// needed -- Docker stores them verbatim. This is why values aren't shell-quoted
|
|
32
|
+
// here, unlike the SSH backend which builds a shell command string.
|
|
33
|
+
args.push('-e', `${key}=${val}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// docker exec requires the container and command after all flags. Furthermore, '--'
|
|
37
|
+
// terminates flag parsing so the container is always treated as a positional argument.
|
|
38
|
+
// Without this, a name like '--privileged' would be parsed as a flag, overriding the
|
|
39
|
+
// exec options above.
|
|
40
|
+
args.push('--', this.container, 'sh', '-c', command);
|
|
41
|
+
yield* streamProcess('docker', args, {
|
|
42
|
+
timeout: options?.timeout,
|
|
43
|
+
signal: options?.signal,
|
|
44
|
+
enoentMessage: 'docker is not installed or not on PATH',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
getTools() {
|
|
48
|
+
const cwd = this.workingDir ? ` Working directory: ${this.workingDir}.` : '';
|
|
49
|
+
return [
|
|
50
|
+
makeFileEditor(this, {
|
|
51
|
+
description: `${DEFAULT_FILE_EDITOR_DESCRIPTION} Files are in Docker container "${this.container}".`,
|
|
52
|
+
}),
|
|
53
|
+
makeBash(this, {
|
|
54
|
+
description: `${SANDBOX_BASH_DESCRIPTION} Runs in Docker container "${this.container}".${cwd}`,
|
|
55
|
+
}),
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=docker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docker.js","sourceRoot":"","sources":["../../../src/sandbox/docker.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E;gBAC7E,gFAAgF;gBAChF,oEAAoE;gBACpE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC,CAAA;YAClC,CAAC;QACH,CAAC;QAED,oFAAoF;QACpF,uFAAuF;QACvF,qFAAqF;QACrF,sBAAsB;QACtB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;QAEpD,KAAK,CAAC,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE;YACnC,OAAO,EAAE,OAAO,EAAE,OAAO;YACzB,MAAM,EAAE,OAAO,EAAE,MAAM;YACvB,aAAa,EAAE,wCAAwC;SACxD,CAAC,CAAA;IACJ,CAAC;IAEQ,QAAQ;QACf,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,uBAAuB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;QAC5E,OAAO;YACL,cAAc,CAAC,IAAI,EAAE;gBACnB,WAAW,EAAE,GAAG,+BAA+B,mCAAmC,IAAI,CAAC,SAAS,IAAI;aACrG,CAAC;YACF,QAAQ,CAAC,IAAI,EAAE;gBACb,WAAW,EAAE,GAAG,wBAAwB,8BAA8B,IAAI,CAAC,SAAS,KAAK,GAAG,EAAE;aAC/F,CAAC;SACH,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error types for sandbox command and code execution.
|
|
3
|
+
*
|
|
4
|
+
* These are runtime throwables raised by sandbox execution; consumers can
|
|
5
|
+
* branch on them via `instanceof` to distinguish timeouts from aborts.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Thrown by sandbox execution when the configured `timeout` elapses.
|
|
9
|
+
*/
|
|
10
|
+
export declare class SandboxTimeoutError extends Error {
|
|
11
|
+
constructor(seconds: number);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Thrown by sandbox execution when the abort signal fires.
|
|
15
|
+
*/
|
|
16
|
+
export declare class SandboxAbortError extends Error {
|
|
17
|
+
constructor();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Thrown by {@link Sandbox.listFiles} when the path does not exist, distinguishing
|
|
21
|
+
* genuine absence from permission or transport failures (which throw plain errors).
|
|
22
|
+
*/
|
|
23
|
+
export declare class SandboxPathNotFoundError extends Error {
|
|
24
|
+
constructor(path: string);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/sandbox/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;;CAK3C;AAED;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,IAAI,EAAE,MAAM;CAIzB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error types for sandbox command and code execution.
|
|
3
|
+
*
|
|
4
|
+
* These are runtime throwables raised by sandbox execution; consumers can
|
|
5
|
+
* branch on them via `instanceof` to distinguish timeouts from aborts.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Thrown by sandbox execution when the configured `timeout` elapses.
|
|
9
|
+
*/
|
|
10
|
+
export class SandboxTimeoutError extends Error {
|
|
11
|
+
constructor(seconds) {
|
|
12
|
+
super(`Execution timed out after ${seconds} seconds`);
|
|
13
|
+
this.name = 'SandboxTimeoutError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Thrown by sandbox execution when the abort signal fires.
|
|
18
|
+
*/
|
|
19
|
+
export class SandboxAbortError extends Error {
|
|
20
|
+
constructor() {
|
|
21
|
+
super('Execution aborted');
|
|
22
|
+
this.name = 'SandboxAbortError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Thrown by {@link Sandbox.listFiles} when the path does not exist, distinguishing
|
|
27
|
+
* genuine absence from permission or transport failures (which throw plain errors).
|
|
28
|
+
*/
|
|
29
|
+
export class SandboxPathNotFoundError extends Error {
|
|
30
|
+
constructor(path) {
|
|
31
|
+
super(`Path not found: ${path}`);
|
|
32
|
+
this.name = 'SandboxPathNotFoundError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/sandbox/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,6BAA6B,OAAO,UAAU,CAAC,CAAA;QACrD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C;QACE,KAAK,CAAC,mBAAmB,CAAC,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,IAAY;QACtB,KAAK,CAAC,mBAAmB,IAAI,EAAE,CAAC,CAAA;QAChC,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAA;IACxC,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Sandbox, type ExecuteOptions } from './base.js';
|
|
2
|
+
export { PosixShellSandbox } from './posix-shell.js';
|
|
3
|
+
export type { StreamType, StreamChunk, FileInfo, OutputFile, ExecutionResult } from './types.js';
|
|
4
|
+
export { LANGUAGE_PATTERN } from './constants.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAChG,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAuB,MAAM,WAAW,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Sandbox } from './base.js';
|
|
2
|
+
import type { ExecuteOptions } from './base.js';
|
|
3
|
+
import type { ExecutionResult, FileInfo, StreamChunk } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Runs on the host with no isolation. Used as the default when no sandbox is configured.
|
|
6
|
+
*/
|
|
7
|
+
export declare class NotASandboxLocalEnvironment extends Sandbox {
|
|
8
|
+
private _resolvePath;
|
|
9
|
+
executeStreaming(command: string, options?: ExecuteOptions): AsyncGenerator<StreamChunk | ExecutionResult, void, undefined>;
|
|
10
|
+
executeCodeStreaming(code: string, language: string, options?: ExecuteOptions): AsyncGenerator<StreamChunk | ExecutionResult, void, undefined>;
|
|
11
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
12
|
+
writeFile(path: string, content: Uint8Array): Promise<void>;
|
|
13
|
+
removeFile(path: string): Promise<void>;
|
|
14
|
+
listFiles(path: string): Promise<FileInfo[]>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=not-a-sandbox-local-environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-a-sandbox-local-environment.d.ts","sourceRoot":"","sources":["../../../src/sandbox/not-a-sandbox-local-environment.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAI/C,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAWxE;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,OAAO;IACtD,OAAO,CAAC,YAAY;IAIb,gBAAgB,CACrB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,cAAc,GACvB,cAAc,CAAC,WAAW,GAAG,eAAe,EAAE,IAAI,EAAE,SAAS,CAAC;IAQ1D,oBAAoB,CACzB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,cAAc,GACvB,cAAc,CAAC,WAAW,GAAG,eAAe,EAAE,IAAI,EAAE,SAAS,CAAC;IAqB3D,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAI3C,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;CA0BnD"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { readFile, writeFile, unlink, mkdir, readdir, stat } from 'fs/promises';
|
|
2
|
+
import { dirname, isAbsolute, join } from 'path';
|
|
3
|
+
import { Sandbox } from './base.js';
|
|
4
|
+
import { LANGUAGE_PATTERN, shellQuote } from './constants.js';
|
|
5
|
+
import { SandboxPathNotFoundError } from './errors.js';
|
|
6
|
+
import { streamProcess } from './stream-process.js';
|
|
7
|
+
import { buildShellEnvPrefix } from './posix-shell.js';
|
|
8
|
+
/** Returns true if the error is a missing entry (ENOENT) or a non-directory path component (ENOTDIR). */
|
|
9
|
+
function isMissingPathError(error) {
|
|
10
|
+
if (error === null || typeof error !== 'object' || !('code' in error)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return error.code === 'ENOENT' || error.code === 'ENOTDIR';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Runs on the host with no isolation. Used as the default when no sandbox is configured.
|
|
17
|
+
*/
|
|
18
|
+
export class NotASandboxLocalEnvironment extends Sandbox {
|
|
19
|
+
_resolvePath(path) {
|
|
20
|
+
return isAbsolute(path) ? path : join(process.cwd(), path);
|
|
21
|
+
}
|
|
22
|
+
async *executeStreaming(command, options) {
|
|
23
|
+
const cwd = options?.cwd ?? process.cwd();
|
|
24
|
+
yield* streamProcess('sh', ['-c', `cd ${shellQuote(cwd)} && ${buildShellEnvPrefix(options?.env)}${command}`], {
|
|
25
|
+
timeout: options?.timeout,
|
|
26
|
+
signal: options?.signal,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async *executeCodeStreaming(code, language, options) {
|
|
30
|
+
if (!LANGUAGE_PATTERN.test(language)) {
|
|
31
|
+
throw new Error(`language parameter contains invalid characters: ${language}`);
|
|
32
|
+
}
|
|
33
|
+
const cwd = options?.cwd ?? process.cwd();
|
|
34
|
+
const encoded = btoa(Array.from(new TextEncoder().encode(code), (b) => String.fromCharCode(b)).join(''));
|
|
35
|
+
const eof = `STRANDS_EOF_${crypto.randomUUID().slice(0, 16)}`;
|
|
36
|
+
yield* streamProcess('sh', [
|
|
37
|
+
'-c',
|
|
38
|
+
`cd ${shellQuote(cwd)} && ${buildShellEnvPrefix(options?.env)}base64 -d << '${eof}' | ${language}\n${encoded}\n${eof}`,
|
|
39
|
+
], {
|
|
40
|
+
timeout: options?.timeout,
|
|
41
|
+
signal: options?.signal,
|
|
42
|
+
enoentMessage: `Language interpreter not found: ${language}`,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async readFile(path) {
|
|
46
|
+
return readFile(this._resolvePath(path));
|
|
47
|
+
}
|
|
48
|
+
async writeFile(path, content) {
|
|
49
|
+
const fullPath = this._resolvePath(path);
|
|
50
|
+
await mkdir(dirname(fullPath), { recursive: true });
|
|
51
|
+
await writeFile(fullPath, content);
|
|
52
|
+
}
|
|
53
|
+
async removeFile(path) {
|
|
54
|
+
await unlink(this._resolvePath(path));
|
|
55
|
+
}
|
|
56
|
+
async listFiles(path) {
|
|
57
|
+
const fullPath = this._resolvePath(path);
|
|
58
|
+
let entries;
|
|
59
|
+
try {
|
|
60
|
+
entries = await readdir(fullPath, { withFileTypes: true });
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
// A missing path (or a file where a directory was expected) is non-existence;
|
|
64
|
+
// permission and other errors propagate so callers can surface them.
|
|
65
|
+
if (isMissingPathError(err)) {
|
|
66
|
+
throw new SandboxPathNotFoundError(path);
|
|
67
|
+
}
|
|
68
|
+
throw err;
|
|
69
|
+
}
|
|
70
|
+
const results = [];
|
|
71
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
72
|
+
try {
|
|
73
|
+
const entryStat = await stat(join(fullPath, entry.name));
|
|
74
|
+
results.push({ name: entry.name, isDir: entryStat.isDirectory(), size: entryStat.size });
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
results.push({ name: entry.name });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return results;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=not-a-sandbox-local-environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-a-sandbox-local-environment.js","sourceRoot":"","sources":["../../../src/sandbox/not-a-sandbox-local-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAC/E,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAEtD,yGAAyG;AACzG,SAAS,kBAAkB,CAAC,KAAc;IACxC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC;QACtE,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAA;AAC5D,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,2BAA4B,SAAQ,OAAO;IAC9C,YAAY,CAAC,IAAY;QAC/B,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAA;IAC5D,CAAC;IAED,KAAK,CAAC,CAAC,gBAAgB,CACrB,OAAe,EACf,OAAwB;QAExB,MAAM,GAAG,GAAG,OAAO,EAAE,GAAG,IAA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,EAAE,CAAC;YACzE,IAAI,CAAC;gBACH,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;gBACxD,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC,CAAA;YAC1F,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;YACpC,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF"}
|
|
@@ -9,6 +9,22 @@
|
|
|
9
9
|
import { Sandbox } from './base.js';
|
|
10
10
|
import type { ExecuteOptions } from './base.js';
|
|
11
11
|
import type { ExecutionResult, FileInfo, StreamChunk } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Validate environment variable names against {@link ENV_KEY_PATTERN}.
|
|
14
|
+
* @throws If any key is not a valid POSIX environment variable name.
|
|
15
|
+
*/
|
|
16
|
+
export declare function validateEnvKeys(env: Record<string, string>): void;
|
|
17
|
+
/**
|
|
18
|
+
* Build a shell `export KEY=VALUE && ...` prefix for a command, or `''` when there are none.
|
|
19
|
+
* Keys are validated; values are {@link shellQuote}d. Used by shell-string backends (e.g. SSH);
|
|
20
|
+
* backends that set env via native flags (e.g. Docker's `-e`) call {@link validateEnvKeys} directly.
|
|
21
|
+
*
|
|
22
|
+
* Uses `export` rather than an `env KEY=VALUE` command wrapper so the variables are set in the
|
|
23
|
+
* shell itself and inherited by every stage of a pipeline. `executeCode` runs `base64 ... | <lang>`,
|
|
24
|
+
* and an `env` wrapper would only bind the left side of the pipe, never reaching the interpreter.
|
|
25
|
+
* The trailing `&&` keeps the surrounding `cd ... && <prefix><command>` chain fail-fast.
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildShellEnvPrefix(env?: Record<string, string>): string;
|
|
12
28
|
/**
|
|
13
29
|
* Abstract sandbox that provides shell-based defaults for file and code operations.
|
|
14
30
|
* Assumes a POSIX-compatible shell (sh/bash) on the target.
|
|
@@ -21,6 +37,11 @@ import type { ExecutionResult, FileInfo, StreamChunk } from './types.js';
|
|
|
21
37
|
* Subclasses may override any method with a native implementation for
|
|
22
38
|
* better performance or to handle edge cases (e.g., binary-safe file
|
|
23
39
|
* transfer via Docker stdin pipes, or native API calls for cloud backends).
|
|
40
|
+
*
|
|
41
|
+
* Subclasses must apply `options.env` in `executeStreaming` or it has no effect:
|
|
42
|
+
* backends that build a shell-command string prepend {@link buildShellEnvPrefix};
|
|
43
|
+
* backends that set env via process flags (e.g. Docker's `-e`) call
|
|
44
|
+
* {@link validateEnvKeys} and pass the values directly.
|
|
24
45
|
*/
|
|
25
46
|
export declare abstract class PosixShellSandbox extends Sandbox {
|
|
26
47
|
executeCodeStreaming(code: string, language: string, options?: ExecuteOptions): AsyncGenerator<StreamChunk | ExecutionResult, void, undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posix-shell.d.ts","sourceRoot":"","sources":["../../../src/sandbox/posix-shell.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"posix-shell.d.ts","sourceRoot":"","sources":["../../../src/sandbox/posix-shell.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAG/C,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExE;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAMjE;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAOxE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,8BAAsB,iBAAkB,SAAQ,OAAO;IAC9C,oBAAoB,CACzB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,cAAc,GACvB,cAAc,CAAC,WAAW,GAAG,eAAe,EAAE,IAAI,EAAE,SAAS,CAAC;IAS3D,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAQ3C,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAW3D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOvC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;CAyBnD"}
|
|
@@ -7,8 +7,37 @@
|
|
|
7
7
|
* (Docker containers, SSH connections, cloud runtimes).
|
|
8
8
|
*/
|
|
9
9
|
import { Sandbox } from './base.js';
|
|
10
|
-
import { LANGUAGE_PATTERN } from './constants.js';
|
|
11
|
-
import {
|
|
10
|
+
import { ENV_KEY_PATTERN, LANGUAGE_PATTERN, shellQuote } from './constants.js';
|
|
11
|
+
import { SandboxPathNotFoundError } from './errors.js';
|
|
12
|
+
/**
|
|
13
|
+
* Validate environment variable names against {@link ENV_KEY_PATTERN}.
|
|
14
|
+
* @throws If any key is not a valid POSIX environment variable name.
|
|
15
|
+
*/
|
|
16
|
+
export function validateEnvKeys(env) {
|
|
17
|
+
for (const key of Object.keys(env)) {
|
|
18
|
+
if (!ENV_KEY_PATTERN.test(key)) {
|
|
19
|
+
throw new Error(`Invalid environment variable name: ${key}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Build a shell `export KEY=VALUE && ...` prefix for a command, or `''` when there are none.
|
|
25
|
+
* Keys are validated; values are {@link shellQuote}d. Used by shell-string backends (e.g. SSH);
|
|
26
|
+
* backends that set env via native flags (e.g. Docker's `-e`) call {@link validateEnvKeys} directly.
|
|
27
|
+
*
|
|
28
|
+
* Uses `export` rather than an `env KEY=VALUE` command wrapper so the variables are set in the
|
|
29
|
+
* shell itself and inherited by every stage of a pipeline. `executeCode` runs `base64 ... | <lang>`,
|
|
30
|
+
* and an `env` wrapper would only bind the left side of the pipe, never reaching the interpreter.
|
|
31
|
+
* The trailing `&&` keeps the surrounding `cd ... && <prefix><command>` chain fail-fast.
|
|
32
|
+
*/
|
|
33
|
+
export function buildShellEnvPrefix(env) {
|
|
34
|
+
if (!env || Object.keys(env).length === 0) {
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
validateEnvKeys(env);
|
|
38
|
+
const assignments = Object.entries(env).map(([k, v]) => `${k}=${shellQuote(v)}`);
|
|
39
|
+
return `export ${assignments.join(' ')} && `;
|
|
40
|
+
}
|
|
12
41
|
/**
|
|
13
42
|
* Abstract sandbox that provides shell-based defaults for file and code operations.
|
|
14
43
|
* Assumes a POSIX-compatible shell (sh/bash) on the target.
|
|
@@ -21,6 +50,11 @@ import { shellQuote } from '../utils/shell-quote.js';
|
|
|
21
50
|
* Subclasses may override any method with a native implementation for
|
|
22
51
|
* better performance or to handle edge cases (e.g., binary-safe file
|
|
23
52
|
* transfer via Docker stdin pipes, or native API calls for cloud backends).
|
|
53
|
+
*
|
|
54
|
+
* Subclasses must apply `options.env` in `executeStreaming` or it has no effect:
|
|
55
|
+
* backends that build a shell-command string prepend {@link buildShellEnvPrefix};
|
|
56
|
+
* backends that set env via process flags (e.g. Docker's `-e`) call
|
|
57
|
+
* {@link validateEnvKeys} and pass the values directly.
|
|
24
58
|
*/
|
|
25
59
|
export class PosixShellSandbox extends Sandbox {
|
|
26
60
|
async *executeCodeStreaming(code, language, options) {
|
|
@@ -56,7 +90,11 @@ export class PosixShellSandbox extends Sandbox {
|
|
|
56
90
|
}
|
|
57
91
|
async listFiles(path) {
|
|
58
92
|
const quoted = shellQuote(path);
|
|
59
|
-
|
|
93
|
+
// Exit 77 distinguishes a missing directory from ls's own failures (locale-independent).
|
|
94
|
+
const result = await this.execute(`test -d ${quoted} || exit 77; env QUOTING_STYLE=literal ls -1ap ${quoted}`);
|
|
95
|
+
if (result.exitCode === 77) {
|
|
96
|
+
throw new SandboxPathNotFoundError(path);
|
|
97
|
+
}
|
|
60
98
|
if (result.exitCode !== 0) {
|
|
61
99
|
throw new Error(result.stderr || `Failed to list directory: ${path}`);
|
|
62
100
|
}
|