Secure isolated code execution SDK. Run untrusted code, build projects, or host services in ephemeral containers.
npm install @fermion-app/sandboximport { Sandbox } from '@fermion-app/sandbox'
// Create sandbox
const sandbox = new Sandbox({ apiKey: 'your-api-key' })
await sandbox.create({ shouldBackupFilesystem: false })
// Execute commands
const result = await sandbox.runCommand({
cmd: 'node',
args: ['--version']
})
console.log(result.stdout)
// Write and read files
await sandbox.writeFile({
path: '~/script.js',
content: 'console.log("Hello World")'
})
const response = await sandbox.getFile('~/script.js')
const content = await response.text()
// Clean up
await sandbox.disconnect()- Isolated containers - Secure Linux environments for code execution
- Real-time streaming - WebSocket-based command output streaming
- File operations - Read/write files with binary support
- Public URLs - Expose ports 3000, 1337, 1338 for web services
- Git support - Clone repositories on container startup
- TypeScript - Full type safety and IntelliSense
const sandbox = new Sandbox({ apiKey: 'your-api-key' })
// New container
await sandbox.create({
shouldBackupFilesystem: false, // Persist filesystem after shutdown
gitRepoUrl: 'https://github.com/user/repo.git' // Optional
})
// Or connect to existing
await sandbox.fromSnippet('snippet-id')// Quick commands (< 5 seconds)
const { stdout, stderr } = await sandbox.runCommand({
cmd: 'ls',
args: ['-la']
})
// Long-running with streaming
const { stdout, stderr, exitCode } = await sandbox.runStreamingCommand({
cmd: 'npm',
args: ['install'],
onStdout: data => console.log(data),
onStderr: data => console.error(data)
})// Write file
await sandbox.writeFile({
path: '~/app.js',
content: 'console.log("Hello")'
})
// Read file
const response = await sandbox.getFile('~/app.js')
const text = await response.text()
const buffer = await response.arrayBuffer()// Start a server
await sandbox.runStreamingCommand({
cmd: 'node',
args: ['server.js']
})
// Get public URL
const url = await sandbox.exposePort(3000)
console.log(`Live at: ${url}`)
// https://abc123-3000.run-code.comconst sandbox = new Sandbox({ apiKey: process.env.API_KEY })
await sandbox.create({
gitRepoUrl: 'https://github.com/user/node-app.git'
})
// Install and build
await sandbox.runStreamingCommand({
cmd: 'npm',
args: ['install'],
onStdout: data => process.stdout.write(data)
})
await sandbox.runCommand({
cmd: 'npm',
args: ['run', 'build']
})
// Start server
sandbox.runStreamingCommand({
cmd: 'npm',
args: ['start']
})
const url = await sandbox.exposePort(3000)
console.log(`App running at: ${url}`)new Sandbox({ apiKey })- Initialize client
create(options)- Create new containerfromSnippet(id)- Connect to existing containerrunCommand(options)- Execute command (< 5s)runStreamingCommand(options)- Execute with streamingwriteFile(options)- Write file to containergetFile(path)- Read file from containerexposePort(port)- Get public URL for portdisconnect()- Clean up resourcesisConnected()- Check connection status
All paths must start with ~ (home) or /home/damner:
~/file.js→/home/damner/file.js/home/damner/app/index.js→ absolute path/home/damner/code/app/index.js→ also supported (nested under home)
Public URLs available for:
- Port 3000
- Port 1337
- Port 1338
npm install # Install dependencies
npm run build # Build the packageMIT
For issues and questions, visit GitHub Issues.