87ceec29d9
Adds stdin piping support to `e2b sandbox exec`, so users can do:
```bash
echo "data" | e2b sandbox exec <id> -- cat
cat file.bin | e2b sandbox exec <id> -- python3 -c 'import sys;
print(len(sys.stdin.buffer.read()))'
```
Included:
- JS SDK updates:
- closeStdin()
- supportsStdinClose
- CLI updates:
- detects piped stdin
- streams stdin in 64 KiB chunks
- closes remote stdin on EOF
- graceful fallback for older sandbox versions (requires `envd` >= 0.5.2, warn + ignore piped input)
### Example Usage
#### non-piped exec still works
```
e2b sandbox exec <sandbox_id> -- 'echo backend-non-pipe'
```
#### piped stdin path (supported envd) should deliver bytes
```
echo "hello" | e2b sandbox exec <sandbox_id> -- 'wc -c' # expect 6
printf '\x00\x01\x02\xff' | $e2b sandbox exec <sandbox_id> -- 'wc -c' #
expect 4
```
#### optional: legacy template behavior should warn + ignore piped stdin
```
echo "hello" | e2b sandbox exec <legacy_sandbox_id> -- 'wc -c' # expect
0 + "Ignoring piped stdin."
```
What is E2B?
E2B is an open-source infrastructure that allows you to run AI-generated code in secure isolated sandboxes in the cloud. To start and control sandboxes, use our JavaScript SDK or Python SDK.
Run your first Sandbox
1. Install SDK
npm i @e2b/code-interpreter
2. Get your E2B API key
E2B_API_KEY=e2b_***
3. Execute code with code interpreter inside Sandbox
import { Sandbox } from '@e2b/code-interpreter'
const sbx = await Sandbox.create()
await sbx.runCode('x = 1')
const execution = await sbx.runCode('x+=1; x')
console.log(execution.text) // outputs 2
4. Check docs
Visit E2B documentation.
5. E2B cookbook
Visit our Cookbook to get inspired by examples with different LLMs and AI frameworks.
