
Product
Redesigned Repositories Page: A Faster Way to Prioritize Security Risk
Our redesigned Repositories page adds alert severity, filtering, and tabs for faster triage and clearer insights across all your projects.
@devbookhq/sdk
Advanced tools
Devbook allows visitors of your docs to interact with and execute any code snippet or shell command in a private VM
Devbook makes your dev docs interactive with just 3 lines of code.
Devbook is a JS library that allows visitors of your docs to interact with and execute any code snippet or shell command in a private VM.
Check out the UI Devbook library that you can use in your documentation.
Every time a user visits a page where you use Devbook (like your docs), we quickly spin up a private VM just for that user. They can experiment and explore your API/SDK right from your docs. Zero setup and overhead.
Check this Twitter thread with a video to see Devbook in action.
npm install @devbookhq/sdk
// 1. Import the hook
import {
useDevbook,
Env,
DevbookStatus,
} from '@devbookhq/sdk'
// 2. Define your code
const code = `
> Code that you want to execute in a VM goes here.
`
function InteractiveCodeSnippet() {
// 3. Use the hook
const { stdout, stderr, status, runCode, url, fs } = useDevbook({ env: Env.NodeJS, port: 3000 })
function handleRun() {
// 4. Execute the code
runCode(code)
}
async function handleFS() {
if (status !== DevbookStatus.Connected) return
// 5. Manipulate the filesystem
await dbk.fs.write('/index.js', 'console.log("Hello world!")')
const content = await dbk.fs.get('/index.js')
console.log('Content of the "/index.js" file', content)
}
return (
<div>
{status === DevbookStatus.Disconnected && <div>Status: Disconnected, will start VM</div>}
{status === DevbookStatus.Connecting && <div>Status: Starting VM...</div>}
{status === DevbookStatus.Connected &&
<>
<div>URL for the port 3000 on the VM: {url}</div>
<button onClick={handleRun}>Run</button>
<button onClick={handleFS}>Test FS</button>
</>
)}
<h3>Output</h3>
{stdout.map((o, idx) => <span key={`out_${idx}`}>{o}</span>)}
{stderr.map((e, idx) => <span key={`err_${idx}`}>{e}</span>)}
</div>
)
}
export default InteractiveCodeSnippet
// 1. Import the class
import { Devbook, Env, DevbookStatus } from '@devbookhq/sdk'
// 2. Define your code
const code = `
> Code that you want to execute in a VM goes here.
`
// 3. Create new Devbook instance
const dbk = new Devbook({
env: Env.NodeJS,
onStdout(out) {
console.log('stdout', { err })
},
onStderr(err) {
console.log('stderr', { err })
},
onStatusChange(status) {
console.log('status', { status })
},
onURLChange(getURL) {
const url = getURL(3000) // Create a URL that connects to the port 3000
console.log('url', { url })
},
})
if (dbk.status === DevbookStatus.Connected) {
// 4. Execute the code
dbk.runCode(code)
// 5. Manipulate the filesystem
await dbk.fs.write('/index.js', 'console.log("Hello world!")')
const content = await dbk.fs.get('/index.js')
console.log('Content of the "/index.js" file', content)
}
FAQs
SDK for managing Devbook sessions from JavaScript/TypeScript
The npm package @devbookhq/sdk receives a total of 92 weekly downloads. As such, @devbookhq/sdk popularity was classified as not popular.
We found that @devbookhq/sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Our redesigned Repositories page adds alert severity, filtering, and tabs for faster triage and clearer insights across all your projects.
Security News
Slopsquatting is a new supply chain threat where AI-assisted code generators recommend hallucinated packages that attackers register and weaponize.
Security News
Multiple deserialization flaws in PyTorch Lightning could allow remote code execution when loading untrusted model files, affecting versions up to 2.4.0.