Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
feat(docs): Code snippets highlighting (#124)
Pavel 'Strajk' Dolecekfc1dafbf8d8b
diff --git a/apps/docs/src/app/_original-template-examples/attachments/page.mdx b/apps/docs/_original-template-examples/attachments/page.mdxsimilarity index 100%rename from apps/docs/src/app/_original-template-examples/attachments/page.mdxrename to apps/docs/_original-template-examples/attachments/page.mdxdiff --git a/apps/docs/src/app/_original-template-examples/authentication/page.mdx b/apps/docs/_original-template-examples/authentication/page.mdxsimilarity index 100%rename from apps/docs/src/app/_original-template-examples/authentication/page.mdxrename to apps/docs/_original-template-examples/authentication/page.mdxdiff --git a/apps/docs/src/app/_original-template-examples/contacts/page.mdx b/apps/docs/_original-template-examples/contacts/page.mdxsimilarity index 100%rename from apps/docs/src/app/_original-template-examples/contacts/page.mdxrename to apps/docs/_original-template-examples/contacts/page.mdxdiff --git a/apps/docs/src/app/_original-template-examples/conversations/page.mdx b/apps/docs/_original-template-examples/conversations/page.mdxsimilarity index 100%rename from apps/docs/src/app/_original-template-examples/conversations/page.mdxrename to apps/docs/_original-template-examples/conversations/page.mdxdiff --git a/apps/docs/src/app/_original-template-examples/errors/page.mdx b/apps/docs/_original-template-examples/errors/page.mdxsimilarity index 100%rename from apps/docs/src/app/_original-template-examples/errors/page.mdxrename to apps/docs/_original-template-examples/errors/page.mdxdiff --git a/apps/docs/src/app/_original-template-examples/groups/page.mdx b/apps/docs/_original-template-examples/groups/page.mdxsimilarity index 100%rename from apps/docs/src/app/_original-template-examples/groups/page.mdxrename to apps/docs/_original-template-examples/groups/page.mdxdiff --git a/apps/docs/src/app/_original-template-examples/messages/page.mdx b/apps/docs/_original-template-examples/messages/page.mdxsimilarity index 100%rename from apps/docs/src/app/_original-template-examples/messages/page.mdxrename to apps/docs/_original-template-examples/messages/page.mdxdiff --git a/apps/docs/src/app/_original-template-examples/pagination/page.mdx b/apps/docs/_original-template-examples/pagination/page.mdxsimilarity index 100%rename from apps/docs/src/app/_original-template-examples/pagination/page.mdxrename to apps/docs/_original-template-examples/pagination/page.mdxdiff --git a/apps/docs/src/app/_original-template-examples/quickstart/page.mdx b/apps/docs/_original-template-examples/quickstart/page.mdxsimilarity index 100%rename from apps/docs/src/app/_original-template-examples/quickstart/page.mdxrename to apps/docs/_original-template-examples/quickstart/page.mdxdiff --git a/apps/docs/src/app/_original-template-examples/sdks/page.mdx b/apps/docs/_original-template-examples/sdks/page.mdxsimilarity index 100%rename from apps/docs/src/app/_original-template-examples/sdks/page.mdxrename to apps/docs/_original-template-examples/sdks/page.mdxdiff --git a/apps/docs/src/app/_original-template-examples/webhooks/page.mdx b/apps/docs/_original-template-examples/webhooks/page.mdxsimilarity index 100%rename from apps/docs/src/app/_original-template-examples/webhooks/page.mdxrename to apps/docs/_original-template-examples/webhooks/page.mdxdiff --git a/apps/docs/package.json b/apps/docs/package.jsonindex d95f1656c..1dc8c4c4d 100644--- a/apps/docs/package.json+++ b/apps/docs/package.json@@ -7,7 +7,8 @@"build": "next build","start": "next start","lint": "next lint",- "format": "prettier --write ."+ "format": "prettier --write .",+ "rm-next-cache": "rm -rf .next/cache"},"browserslist": "defaults, not ie <= 11","dependencies": {diff --git a/apps/docs/src/code/js/basics/fs_ls.js b/apps/docs/src/code/js/basics/fs_ls.jsindex 5cf9fd20a..aebd7fbbc 100644--- a/apps/docs/src/code/js/basics/fs_ls.js+++ b/apps/docs/src/code/js/basics/fs_ls.js@@ -5,7 +5,7 @@ const session = await Session.create({apiKey: process.env.E2B_API_KEY,})-const dirContent = await session.filesystem.list('/')+const dirContent = await session.filesystem.list('/') // $HighlightLinedirContent.forEach((item) => {console.log(item.name)})diff --git a/apps/docs/src/code/js/basics/fs_mkdir.js b/apps/docs/src/code/js/basics/fs_mkdir.jsindex c07ec5865..e6018da8a 100644--- a/apps/docs/src/code/js/basics/fs_mkdir.js+++ b/apps/docs/src/code/js/basics/fs_mkdir.js@@ -7,6 +7,6 @@ const session = await Session.create({// `filesystem.make_dir()` will fail if any directory in the path doesn't exist// Create a new directory '/dir'-await session.filesystem.makeDir('/dir')+await session.filesystem.makeDir('/dir') // $HighlightLineawait session.close()diff --git a/apps/docs/src/code/js/basics/fs_read.js b/apps/docs/src/code/js/basics/fs_read.jsindex 7b6950ed3..6d108b754 100644--- a/apps/docs/src/code/js/basics/fs_read.js+++ b/apps/docs/src/code/js/basics/fs_read.js@@ -5,7 +5,7 @@ const session = await Session.create({apiKey: process.env.E2B_API_KEY,})-const fileContent = await session.filesystem.read('/etc/hosts')+const fileContent = await session.filesystem.read('/etc/hosts') // $HighlightLineconsole.log(fileContent)await session.close()diff --git a/apps/docs/src/code/js/basics/fs_watch.js b/apps/docs/src/code/js/basics/fs_watch.jsindex 1fda7be40..025fdbb6c 100644--- a/apps/docs/src/code/js/basics/fs_watch.js+++ b/apps/docs/src/code/js/basics/fs_watch.js@@ -6,11 +6,11 @@ const session = await Session.create({})// Start filesystem watcher for the /home directory-const watcher = session.filesystem.watchDir('/home')+const watcher = session.filesystem.watchDir('/home') // $HighlightLinewatcher.addEventListener(event => {console.log('Filesystem event', event)})-await watcher.start()+await watcher.start() // $HighlightLine// Create files in the /home directory inside the playgrounddiff --git a/apps/docs/src/code/js/basics/fs_write.js b/apps/docs/src/code/js/basics/fs_write.jsindex 517981843..6542b6899 100644--- a/apps/docs/src/code/js/basics/fs_write.js+++ b/apps/docs/src/code/js/basics/fs_write.js@@ -11,7 +11,7 @@ const session = await Session.create({// - overwrite the file if it exists// Write the content of the file '/hello.txt'-await session.filesystem.write("/hello.txt", "Hello World!")+await session.filesystem.write("/hello.txt", "Hello World!") // $HighlightLine// The following would fail because '/dir' doesn't exist// await session.filesystem.write("/dir/hello.txt", "Hello World!")diff --git a/apps/docs/src/code/js/basics/get_url.js b/apps/docs/src/code/js/basics/get_url.jsindex fd41b7587..8bf54bab4 100644--- a/apps/docs/src/code/js/basics/get_url.js+++ b/apps/docs/src/code/js/basics/get_url.js@@ -5,7 +5,7 @@ const session = await Session.create({apiKey: process.env.E2B_API_KEY,})-const url = session.getHostname()+const url = session.getHostname() // $HighlightLineconsole.log('https://' + url)-await session.close()\ No newline at end of file+await session.close()diff --git a/apps/docs/src/code/js/basics/get_url_port.js b/apps/docs/src/code/js/basics/get_url_port.jsindex 500b56771..ace906dee 100644--- a/apps/docs/src/code/js/basics/get_url_port.js+++ b/apps/docs/src/code/js/basics/get_url_port.js@@ -5,7 +5,7 @@ const session = await Session.create({apiKey: process.env.E2B_API_KEY,})-const url = session.getHostname(3000)+const url = session.getHostname(3000) // $HighlightLineconsole.log('https://' + url)-await session.close()\ No newline at end of file+await session.close()diff --git a/apps/docs/src/code/js/basics/init.js b/apps/docs/src/code/js/basics/init.jsindex 80ac63280..e09965ebc 100644--- a/apps/docs/src/code/js/basics/init.js+++ b/apps/docs/src/code/js/basics/init.js@@ -1,10 +1,9 @@import { Session } from '@e2b/sdk'-// `id` can also be one of:-// 'Nodejs', 'Bash', 'Python3', 'Java', 'Go', 'Rust', 'PHP', 'Perl', 'DotNET'-// We're working on custom environments.const session = await Session.create({- id: 'Nodejs',+ // We're working on custom environments+ id: 'Nodejs', // or 'Bash', 'Python3', 'Java', 'Go', 'Rust', 'PHP', 'Perl', 'DotNET'apiKey: process.env.E2B_API_KEY,})-await session.close()\ No newline at end of file++await session.close()diff --git a/apps/docs/src/code/js/basics/process_start.js b/apps/docs/src/code/js/basics/process_start.jsindex f69d27392..5bd6db6ab 100644--- a/apps/docs/src/code/js/basics/process_start.js+++ b/apps/docs/src/code/js/basics/process_start.js@@ -5,11 +5,11 @@ const session = await Session.create({apiKey: process.env.E2B_API_KEY,})-const npmInit = await session.process.start({+const npmInit = await session.process.start({ // $HighlightLinecmd: 'npm init -y'})await npmInit.finishedconsole.log(npmInit.output.stdout)-await session.close()\ No newline at end of file+await session.close()diff --git a/apps/docs/src/code/js/basics/process_stop.js b/apps/docs/src/code/js/basics/process_stop.jsindex 88f00673a..5c8aa2acf 100644--- a/apps/docs/src/code/js/basics/process_stop.js+++ b/apps/docs/src/code/js/basics/process_stop.js@@ -8,8 +8,8 @@ const session = await Session.create({const npmInit = await session.process.start({cmd: 'npm init -y'})-await npmInit.kill()-// There will be no output because we immediatelly kill the `npm_init` process+await npmInit.kill() // $HighlightLine+// There will be no output because we immediately kill the `npm_init` processconsole.log(npmInit.output.stdout)-await session.close()\ No newline at end of file+await session.close()diff --git a/apps/docs/src/code/js/basics/process_stream_stderr.js b/apps/docs/src/code/js/basics/process_stream_stderr.jsindex 9e7e8b53e..aa19b39af 100644--- a/apps/docs/src/code/js/basics/process_stream_stderr.js+++ b/apps/docs/src/code/js/basics/process_stream_stderr.js@@ -8,8 +8,8 @@ const session = await Session.create({// This command will fail and output to stderr because Golang isn't installed in the cloud playgroundconst golangVersion = await session.process.start({cmd: 'go version',- onStderr: output => console.log(output), // Print stderr to console+ onStderr: output => console.log(output), // $HighlightLine})await golangVersion.finished-await session.close()\ No newline at end of file+await session.close()diff --git a/apps/docs/src/code/js/basics/process_stream_stdout.js b/apps/docs/src/code/js/basics/process_stream_stdout.jsindex 8ed9fbc6b..7b8abc1aa 100644--- a/apps/docs/src/code/js/basics/process_stream_stdout.js+++ b/apps/docs/src/code/js/basics/process_stream_stdout.js@@ -7,8 +7,8 @@ const session = await Session.create({const npmInit = await session.process.start({cmd: 'npm init -y',- onStdout: output => console.log(output),+ onStdout: output => console.log(output), // $HighlightLine})await npmInit.finished-await session.close()\ No newline at end of file+await session.close()diff --git a/apps/docs/src/code/js/basics/process_write_stdin.js b/apps/docs/src/code/js/basics/process_write_stdin.jsindex 94b0cd06e..a312512c8 100644--- a/apps/docs/src/code/js/basics/process_write_stdin.js+++ b/apps/docs/src/code/js/basics/process_write_stdin.js@@ -11,7 +11,7 @@ const proc = await session.process.start({cmd: 'while IFS= read -r line; do echo \"$line\"; sleep 1; done',onStdout: output => console.log(output),})-await proc.sendStdin("AI Playground\n")+await proc.sendStdin("AI Playground\n") // $HighlightLineawait proc.kill()-await session.close()\ No newline at end of file+await session.close()diff --git a/apps/docs/src/code/js/basics/scan_ports.js b/apps/docs/src/code/js/basics/scan_ports.jsindex 26596e87e..94244cbf3 100644--- a/apps/docs/src/code/js/basics/scan_ports.js+++ b/apps/docs/src/code/js/basics/scan_ports.js@@ -23,11 +23,11 @@ function printNewPortAndURL(openPorts, session) {const session = await Session.create({id: 'Python3',apiKey: process.env.E2B_API_KEY,- onScanPorts: openPorts => printNewPortAndURL(openPorts, session)+ onScanPorts: openPorts => printNewPortAndURL(openPorts, session) // $HighlightLine})// Start a new server on port 8000 inside the playground.-const proc = await session.process.start({ cmd: 'python3 -m http.server 8000' })+const proc = await session.process.start({ cmd: 'python3 -m http.server 8000' }) // $HighlightLine// Wait 10 seconds and then kill the server and close the session.@@ -35,4 +35,4 @@ await sleep(10000)await proc.kill()await session.close()-await session.close()\ No newline at end of file+await session.close()diff --git a/apps/docs/src/code/js/logging/e2b_logging.js b/apps/docs/src/code/js/logging/e2b_logging.jsindex 8dfe569c7..e92bee1e1 100644--- a/apps/docs/src/code/js/logging/e2b_logging.js+++ b/apps/docs/src/code/js/logging/e2b_logging.js@@ -11,5 +11,5 @@ const logger = {const session = await Session.create({id: 'Nodejs',apiKey: process.env.E2B_API_KEY,- logger,+ logger, // $HighlightLine})diff --git a/apps/docs/src/code/js/quickstart.js b/apps/docs/src/code/js/quickstart.jsindex 4bf387adb..e09965ebc 100644--- a/apps/docs/src/code/js/quickstart.js+++ b/apps/docs/src/code/js/quickstart.js@@ -1,10 +1,8 @@import { Session } from '@e2b/sdk'-// `id` can also be one of:-// 'Nodejs', 'Bash', 'Python3', 'Java', 'Go', 'Rust', 'PHP', 'Perl', 'DotNET'-// We're working on custom environments.const session = await Session.create({- id: 'Nodejs',+ // We're working on custom environments+ id: 'Nodejs', // or 'Bash', 'Python3', 'Java', 'Go', 'Rust', 'PHP', 'Perl', 'DotNET'apiKey: process.env.E2B_API_KEY,})diff --git a/apps/docs/src/code/js/timeout/timeout_filesystem.js b/apps/docs/src/code/js/timeout/timeout_filesystem.jsindex 6d62a2589..f0b6269ab 100644--- a/apps/docs/src/code/js/timeout/timeout_filesystem.js+++ b/apps/docs/src/code/js/timeout/timeout_filesystem.js@@ -6,12 +6,12 @@ const session = await Session.create({})// Timeout for the write operation-await session.filesystem.write('hello.txt', 'Hello World!', { timeout: 3000 })+await session.filesystem.write('hello.txt', 'Hello World!', { timeout: 3000 }) // $HighlightLine// Timeout for the list operation-const files = await session.filesystem.list('.', { timeout: 3000 })+const files = await session.filesystem.list('.', { timeout: 3000 }) // $HighlightLine// Timeout for the read operation-const content = await session.filesystem.read('hello.txt', { timeout: 3000 })+const content = await session.filesystem.read('hello.txt', { timeout: 3000 }) // $HighlightLineawait session.close()diff --git a/apps/docs/src/code/js/timeout/timeout_process.js b/apps/docs/src/code/js/timeout/timeout_process.jsindex eea4114d0..2a71ec6c9 100644--- a/apps/docs/src/code/js/timeout/timeout_process.js+++ b/apps/docs/src/code/js/timeout/timeout_process.js@@ -8,7 +8,7 @@ const session = await Session.create({// Timeout for the process to startconst npmInit = await session.process.start({cmd: 'npm init -y',- timeout: 3000,+ timeout: 3000, // $HighlightLine})await npmInit.finisheddiff --git a/apps/docs/src/code/js/timeout/timeout_session.js b/apps/docs/src/code/js/timeout/timeout_session.jsindex aec4dd25f..4cdbfe726 100644--- a/apps/docs/src/code/js/timeout/timeout_session.js+++ b/apps/docs/src/code/js/timeout/timeout_session.js@@ -4,7 +4,7 @@ import { Session } from '@e2b/sdk'const session = await Session.create({id: 'Nodejs',apiKey: process.env.E2B_API_KEY,- timeout: 3000,+ timeout: 3000, // $HighlightLine})await session.close()diff --git a/apps/docs/src/code/python/basics/fs_ls.py b/apps/docs/src/code/python/basics/fs_ls.pyindex 82cf70ad8..5e6bae933 100644--- a/apps/docs/src/code/python/basics/fs_ls.py+++ b/apps/docs/src/code/python/basics/fs_ls.py@@ -8,10 +8,10 @@ async def main():session = await Session.create(id="Nodejs", api_key=E2B_API_KEY)# List the root directory- content = await session.filesystem.list("/")+ content = await session.filesystem.list("/") # $HighlightLinefor item in content:print(item.name, "Is directory?", item.is_dir)await session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/basics/fs_mkdir.py b/apps/docs/src/code/python/basics/fs_mkdir.pyindex bf758ee7a..222ba2065 100644--- a/apps/docs/src/code/python/basics/fs_mkdir.py+++ b/apps/docs/src/code/python/basics/fs_mkdir.py@@ -10,8 +10,8 @@ async def main():# `filesystem.make_dir()` will fail if any directory in the path doesn't exist# Create a new directory '/dir'- await session.filesystem.make_dir("/dir")+ await session.filesystem.make_dir("/dir") # $HighlightLineawait session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/basics/fs_read.py b/apps/docs/src/code/python/basics/fs_read.pyindex b9d474477..e5d8f94e1 100644--- a/apps/docs/src/code/python/basics/fs_read.py+++ b/apps/docs/src/code/python/basics/fs_read.py@@ -8,7 +8,7 @@ async def main():session = await Session.create(id="Nodejs", api_key=E2B_API_KEY)# Read the '/etc/hosts' file- file_content = await session.filesystem.read('/etc/hosts')+ file_content = await session.filesystem.read('/etc/hosts') # $HighlightLine# Prints something like:# 127.0.0.1 localhost@@ -16,4 +16,4 @@ async def main():await session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/basics/fs_watch.py b/apps/docs/src/code/python/basics/fs_watch.pyindex 568148d16..7e0fc948b 100644--- a/apps/docs/src/code/python/basics/fs_watch.py+++ b/apps/docs/src/code/python/basics/fs_watch.py@@ -5,16 +5,16 @@ from e2b import SessionE2B_API_KEY = getenv("E2B_API_KEY")watcher = None-async def create_watcher(session):- # Start filesystem watcher for the /home directory- watcher = await session.filesystem.watch_dir("/home")- watcher.add_event_listener(lambda event: print(event))- await watcher.start()+async def create_watcher(session): # $HighlightLine+ # Start filesystem watcher for the /home directory # $HighlightLine+ watcher = await session.filesystem.watch_dir("/home") # $HighlightLine+ watcher.add_event_listener(lambda event: print(event)) # $HighlightLine+ await watcher.start() # $HighlightLineasync def main():session = await Session.create(id="Nodejs", api_key=E2B_API_KEY)- await create_watcher(session)+ await create_watcher(session) # $HighlightLine# Create files in the /home directory inside the playground# We'll receive notifications for these events through the watcher we created above.@@ -27,4 +27,4 @@ async def main():await session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/basics/fs_write.py b/apps/docs/src/code/python/basics/fs_write.pyindex c60de92ba..d4ced13d7 100644--- a/apps/docs/src/code/python/basics/fs_write.py+++ b/apps/docs/src/code/python/basics/fs_write.py@@ -13,11 +13,11 @@ async def main():# - overwrite the file if it exists# Write the content of the file '/hello.txt'- await session.filesystem.write("/hello.txt", "Hello World!")+ await session.filesystem.write("/hello.txt", "Hello World!") # $HighlightLine# The following would fail because '/dir' doesn't exist# await session.filesystem.write("/dir/hello.txt", "Hello World!")await session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/basics/get_url.py b/apps/docs/src/code/python/basics/get_url.pyindex 1e1377839..f7aeb4423 100644--- a/apps/docs/src/code/python/basics/get_url.py+++ b/apps/docs/src/code/python/basics/get_url.py@@ -6,8 +6,8 @@ E2B_API_KEY = getenv("E2B_API_KEY")async def main():session = await Session.create(id="Nodejs", api_key=E2B_API_KEY)- url = session.get_hostname()+ url = session.get_hostname() # $HighlightLineprint("https://" + url)await session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/basics/get_url_port.py b/apps/docs/src/code/python/basics/get_url_port.pyindex 276545a50..8f5812b72 100644--- a/apps/docs/src/code/python/basics/get_url_port.py+++ b/apps/docs/src/code/python/basics/get_url_port.py@@ -7,9 +7,9 @@ E2B_API_KEY = getenv("E2B_API_KEY")async def main():session = await Session.create(id="Nodejs", api_key=E2B_API_KEY)- url = session.get_hostname(3000)+ url = session.get_hostname(3000) # $HighlightLineprint("https://" + url)await session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/basics/process_start.py b/apps/docs/src/code/python/basics/process_start.pyindex bda8327f4..eabfe870b 100644--- a/apps/docs/src/code/python/basics/process_start.py+++ b/apps/docs/src/code/python/basics/process_start.py@@ -7,10 +7,10 @@ E2B_API_KEY = getenv("E2B_API_KEY")async def main():session = await Session.create(id="Nodejs", api_key=E2B_API_KEY)- npm_init = await session.process.start("npm init -y")+ npm_init = await session.process.start("npm init -y") # $HighlightLineawait npm_initprint(npm_init.stdout)await session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/basics/process_stop.py b/apps/docs/src/code/python/basics/process_stop.pyindex dbbb7657d..3bd9731ee 100644--- a/apps/docs/src/code/python/basics/process_stop.py+++ b/apps/docs/src/code/python/basics/process_stop.py@@ -8,10 +8,10 @@ async def main():session = await Session.create(id="Nodejs", api_key=E2B_API_KEY)npm_init = await session.process.start("npm init -y")- await npm_init.kill()- # There will be no output because we immediatelly kill the `npm_init` process+ await npm_init.kill() # $HighlightLine+ # There will be no output because we immediately kill the `npm_init` processprint(npm_init.stdout)await session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/basics/process_stream_stderr.py b/apps/docs/src/code/python/basics/process_stream_stderr.pyindex c186f3f57..83cac918f 100644--- a/apps/docs/src/code/python/basics/process_stream_stderr.py+++ b/apps/docs/src/code/python/basics/process_stream_stderr.py@@ -13,10 +13,10 @@ async def main():# This command will fail and output to stderr because Golang isn't installed in the cloud playgroundgolang_version = await session.process.start("go version",- on_stderr=print_stderr,+ on_stderr=print_stderr, # $HighlightLine)await golang_versionawait session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/basics/process_stream_stdout.py b/apps/docs/src/code/python/basics/process_stream_stdout.pyindex b8d37b1f0..8bc99cf7b 100644--- a/apps/docs/src/code/python/basics/process_stream_stdout.py+++ b/apps/docs/src/code/python/basics/process_stream_stdout.py@@ -12,10 +12,10 @@ async def main():npm_init = await session.process.start("npm init -y",- on_stdout=print_stdout,+ on_stdout=print_stdout, # $HighlightLine)await npm_initawait session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/basics/process_write_stdin.py b/apps/docs/src/code/python/basics/process_write_stdin.pyindex 5ab861675..e9d32a972 100644--- a/apps/docs/src/code/python/basics/process_write_stdin.py+++ b/apps/docs/src/code/python/basics/process_write_stdin.py@@ -13,9 +13,9 @@ async def main():"while IFS= read -r line; do echo \"$line\"; sleep 1; done",on_stdout=print,)- await proc.send_stdin("AI Playground\n")+ await proc.send_stdin("AI Playground\n") # $HighlightLineawait proc.kill()await session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/basics/scan_ports.py b/apps/docs/src/code/python/basics/scan_ports.pyindex b6ea6f2d9..70f257744 100644--- a/apps/docs/src/code/python/basics/scan_ports.py+++ b/apps/docs/src/code/python/basics/scan_ports.py@@ -26,7 +26,7 @@ async def main():session = await Session.create(id="Python3",api_key=E2B_API_KEY,- on_scan_ports=lambda open_ports: print_new_port_and_url(open_ports, session)+ on_scan_ports=lambda open_ports: print_new_port_and_url(open_ports, session) # $HighlightLine)# Start a new server on port 8000 inside the playground.@@ -37,4 +37,4 @@ async def main():await proc.kill()await session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/logging/e2b_logging.py b/apps/docs/src/code/python/logging/e2b_logging.pyindex 6c8671f4e..7464347cc 100644--- a/apps/docs/src/code/python/logging/e2b_logging.py+++ b/apps/docs/src/code/python/logging/e2b_logging.py@@ -6,16 +6,16 @@ from e2b import SessionE2B_API_KEY = getenv("E2B_API_KEY")# Global logging configuration-logging.basicConfig(level=logging.INFO, format="GLOBAL - [%(asctime)s] - %(name)-32s - %(levelname)7s: %(message)s", datefmt="%Y-%m-%d %H:%M:%S")+logging.basicConfig(level=logging.INFO, format="GLOBAL - [%(asctime)s] - %(name)-32s - %(levelname)7s: %(message)s", datefmt="%Y-%m-%d %H:%M:%S") # $HighlightLine# Or configure only e2b logger# Get e2b logger-e2b_logger = logging.getLogger("e2b")+e2b_logger = logging.getLogger("e2b") # $HighlightLine# Set e2b logger level to INFO-e2b_logger.setLevel(logging.INFO)+e2b_logger.setLevel(logging.INFO) # $HighlightLine# Setup formatterformatter = logging.Formatter("E2B - [%(asctime)s] - %(name)-32s - %(levelname)7s: %(message)s", datefmt="%Y-%m-%d %H:%M:%S")@@ -25,7 +25,7 @@ handler = logging.StreamHandler()handler.setFormatter(formatter)# Add handler to e2b logger-e2b_logger.addHandler(handler)+e2b_logger.addHandler(handler) # $HighlightLineasync def main():diff --git a/apps/docs/src/code/python/timeout/timeout_filesystem.py b/apps/docs/src/code/python/timeout/timeout_filesystem.pyindex 81bfdff01..582f8d3ab 100644--- a/apps/docs/src/code/python/timeout/timeout_filesystem.py+++ b/apps/docs/src/code/python/timeout/timeout_filesystem.py@@ -8,14 +8,14 @@ async def main():session = await Session.create(id="Nodejs", api_key=E2B_API_KEY)# Timeout for the write operation- await session.filesystem.write("test.txt", "Hello World", timeout=3)+ await session.filesystem.write("test.txt", "Hello World", timeout=3) # $HighlightLine# Timeout for the list operation- await session.filesystem.list(".", timeout=3)+ await session.filesystem.list(".", timeout=3) # $HighlightLine# Timeout for the read operation- await session.filesystem.read("test.txt", timeout=3)+ await session.filesystem.read("test.txt", timeout=3) # $HighlightLineawait session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/timeout/timeout_process.py b/apps/docs/src/code/python/timeout/timeout_process.pyindex 3fcf7f80f..13600ec3f 100644--- a/apps/docs/src/code/python/timeout/timeout_process.py+++ b/apps/docs/src/code/python/timeout/timeout_process.py@@ -8,9 +8,9 @@ async def main():session = await Session.create(id="Nodejs", api_key=E2B_API_KEY)# Timeout for the process to start- npm_init = await session.process.start("npm init -y", timeout=5)+ npm_init = await session.process.start("npm init -y", timeout=5) # $HighlightLineawait npm_initawait session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/code/python/timeout/timeout_session.py b/apps/docs/src/code/python/timeout/timeout_session.pyindex e76a3b42f..6e509ce4b 100644--- a/apps/docs/src/code/python/timeout/timeout_session.py+++ b/apps/docs/src/code/python/timeout/timeout_session.py@@ -6,8 +6,8 @@ E2B_API_KEY = getenv("E2B_API_KEY")async def main():# Timeout for the session to open- session = await Session.create(id="Nodejs", api_key=E2B_API_KEY, timeout=5)+ session = await Session.create(id="Nodejs", api_key=E2B_API_KEY, timeout=5) # $HighlightLineawait session.close()-asyncio.run(main())\ No newline at end of file+asyncio.run(main())diff --git a/apps/docs/src/mdx/rehype.mjs b/apps/docs/src/mdx/rehype.mjsindex 37e540a7d..6a84ea137 100644--- a/apps/docs/src/mdx/rehype.mjs+++ b/apps/docs/src/mdx/rehype.mjs@@ -20,31 +20,152 @@ function rehypeParseCodeBlocks() {let highlighter+const elements = {+ pre({ className, style, children }) {+ // return `<pre class="${className}" style="${style}" tabindex="0">${children}</pre>` // original implementation+ return children+ },++ code({ children }) {+ // return `<code>${children}</code>` // original implementation+ return children+ },++ line({ className, children }) {+ return `<span class="${className}">${children}</span>` // no changes here+ },++ token({ style, children }) {+ return `<span style="${style}">${children}</span>` // no changes here+ }+}++// From Shiki+const FontStyle = {+ NotSet: -1,+ None: 0,+ Italic: 1,+ Bold: 2,+ Underline: 4+}+++// Custom implementation of renderToHtml from https://raw.githubusercontent.com/shikijs/shiki/main/packages/shiki/src/renderer.ts+function customRenderToHtml(lines, language) {+ function h(type = '', props = {}, children) {+ const element = elements[type]+ if (element) {+ children = children.filter(Boolean)+ return element({+ ...props,+ children: type === 'code' ? children.join('\n') : children.join('')+ })+ }+ return ''+ }++ return h(+ 'pre',+ { className: 'shiki ' },+ [+ h(+ 'code',+ {},+ lines.map((line, index) => {+ let isE2bImport = false+ if ( // Not perfect, but should work fine for now+ index === 0 // Only supported on the first line+ && line?.some(token => token.content === 'import' && token.color === 'var(--shiki-token-keyword)') // works fine for Python and JS+ && line?.some(token => token.content === 'e2b' && token.color === 'var(--shiki-token-text)') // works fine for Python and JS+ ) {+ isE2bImport = true // TODO: Actually use, probably to dim the line+ }++ let isHighlightComment = false+ if (+ line?.some(token => token.content.includes('$HighlightLine') && token.color === 'var(--shiki-token-comment)')+ ) {+ isHighlightComment = true+ }++ // TODO: Maybe more interesting rules?++ const lineNumber = index + 1+ const lineOptions = []+ let lineClasses = ''++ if (isHighlightComment) {+ // Drop the token with the comment+ // TODO: Dry+ line = line.filter(token => !(token.content.includes('$HighlightLine') && token.color === 'var(--shiki-token-comment)'))+ lineClasses += ' Code-line_highlighted'+ }++ return h(+ 'line',+ {+ className: lineClasses,+ lines,+ line,+ index+ },+ line.map((token, index) => {+ const cssDeclarations = [`color: ${token.color}`]+ if (token.fontStyle === FontStyle.Italic) cssDeclarations.push('font-style: italic')+ if (token.fontStyle === FontStyle.Bold) cssDeclarations.push('font-weight: bold')+ if (token.fontStyle === FontStyle.Underline) cssDeclarations.push('text-decoration: underline')++ return h(+ 'token',+ {+ style: cssDeclarations.join('; '),+ tokens: line,+ token,+ index+ },+ [escapeHtml(token.content)]+ )+ })+ )+ })+ )+ ]+ )+}++const htmlEscapes = {+ '&': '&',+ '<': '<',+ '>': '>',+ '"': '"',+ "'": '''+}++function escapeHtml(html) {+ return html.replace(/[&<>"']/g, chr => htmlEscapes[chr])+}+function rehypeShiki() {return async (tree) => {- highlighter =- highlighter ?? (await shiki.getHighlighter({ theme: 'css-variables' }))+ highlighter = highlighter ?? (await shiki.getHighlighter({ theme: 'css-variables' }))visit(tree, 'element', (node) => {if (node.tagName === 'pre' && node.children[0]?.tagName === 'code') {+ const { language } = node.properties;let codeNode = node.children[0]let textNode = codeNode.children[0]-- node.properties.code = textNode.value-- if (node.properties.language) {- let tokens = highlighter.codeToThemedTokens(- textNode.value,- node.properties.language- )-- textNode.value = shiki.renderToHtml(tokens, {- elements: {- pre: ({ children }) => children,- code: ({ children }) => children,- line: ({ children }) => `<span>${children}</span>`,- },- })+ const code = textNode.value;++ node.properties.code = code // TODO: Explain why we need this++ if (language) {+ let tokens = highlighter.codeToThemedTokens(code, language)++ // Custom renderer for out magic comments+ // Normally, we would call textNode.value = shiki.renderToHtml(tokens)+ // Tokens are in format [{ content: 'const', color: 'var(--shiki-token-keyword)' }, ...]+ // We don't get full AST here, so when we wanna target code comments for our styling, we need to find them by matching `color`+ textNode.value = customRenderToHtml(tokens, language)}}})diff --git a/apps/docs/src/styles/tailwind.css b/apps/docs/src/styles/tailwind.cssindex 6673210f0..09d51495b 100644--- a/apps/docs/src/styles/tailwind.css+++ b/apps/docs/src/styles/tailwind.css@@ -11,6 +11,28 @@--shiki-token-punctuation: theme('colors.zinc.200');}+ code[class*='language-'] .Code-line_highlighted {+ position: relative; /* holds highlight element */+ z-index: 1; /* force above the highlight defined below */+ }++ code[class*='language-'] .Code-line_highlighted:before {+ content: '';+ position: absolute;+ left: -16px; /* align nicely with code border */+ top: -5px; bottom: -5px; /* breathing space */+ border-left: 3px solid theme('colors.emerald.500');+ width: 300px; /* arbitrary value, looks nice */+ /* TODO: Theme colors */+ background: linear-gradient(+ to right,+ hsl(240, 3%, 21%),+ #1d1d20+ );+ pointer-events: none;+ z-index: -1; /* force below code */+ }+[inert] ::-webkit-scrollbar {display: none;}