Vibengine
Sandbox

Internet Access

How sandboxes connect to the internet

Internet Access

Every Vibengine sandbox has full outbound internet access by default. Sandboxes can download packages, make HTTP requests, clone repositories, and communicate with any external API or service.

Outbound Access

Sandboxes can reach the public internet without any configuration. This means you can:

  • Install packages from npm, PyPI, apt, and other registries
  • Make HTTP/HTTPS requests to external APIs
  • Clone Git repositories
  • Download files from the web
  • Connect to databases and external services
import { Sandbox } from 'vibengine'

const sandbox = await Sandbox.create()

// Install packages from the internet
await sandbox.commands.run('pip install requests flask')

// Make an HTTP request
const result = await sandbox.commands.run('curl -s https://httpbin.org/ip')
console.log(result.stdout) // {"origin": "..."}

// Clone a repository
await sandbox.commands.run('git clone https://github.com/vibengine/examples.git /home/user/examples')
from vibengine import Sandbox

sandbox = Sandbox.create()

# Install packages from the internet
sandbox.commands.run("pip install requests flask")

# Make an HTTP request
result = sandbox.commands.run("curl -s https://httpbin.org/ip")
print(result.stdout)  # {"origin": "..."}

# Clone a repository
sandbox.commands.run("git clone https://github.com/vibengine/examples.git /home/user/examples")

Running Web Servers

You can run web servers, APIs, and other network services inside a sandbox. Each sandbox exposes services through a unique hostname.

import { Sandbox } from 'vibengine'

const sandbox = await Sandbox.create()

// Start a web server in the background
await sandbox.commands.run('python3 -m http.server 8080', {
  background: true,
})

// Get the public URL for port 8080
const hostname = sandbox.getHostname(8080)
console.log(`Server accessible at: https://${hostname}`)
from vibengine import Sandbox

sandbox = Sandbox.create()

# Start a web server in the background
sandbox.commands.run("python3 -m http.server 8080", background=True)

# Get the public URL for port 8080
hostname = sandbox.get_hostname(8080)
print(f"Server accessible at: https://{hostname}")

The hostname returned by getHostname() is a publicly accessible URL. You can share it or use it to connect to services running inside the sandbox from your own application.

Accessing Sandbox Services from Outside

Once you have the hostname, you can access services running inside the sandbox from anywhere on the internet.

import { Sandbox } from 'vibengine'

const sandbox = await Sandbox.create()

// Write and start a simple API server
await sandbox.files.write('/home/user/server.py', `
from http.server import HTTPServer, BaseHTTPRequestHandler
import json

class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-Type", "application/json")
        self.end_headers()
        self.wfile.write(json.dumps({"status": "ok"}).encode())

HTTPServer(("0.0.0.0", 3000), Handler).serve_forever()
`)

await sandbox.commands.run('python3 /home/user/server.py', {
  background: true,
})

// Get the public URL
const hostname = sandbox.getHostname(3000)
console.log(`API available at: https://${hostname}`)

// You can now fetch from this URL in your application
const response = await fetch(`https://${hostname}`)
const data = await response.json()
console.log(data) // { status: "ok" }
import requests
from vibengine import Sandbox

sandbox = Sandbox.create()

# Write and start a simple API server
sandbox.files.write("/home/user/server.py", """
from http.server import HTTPServer, BaseHTTPRequestHandler
import json

class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-Type", "application/json")
        self.end_headers()
        self.wfile.write(json.dumps({"status": "ok"}).encode())

HTTPServer(("0.0.0.0", 3000), Handler).serve_forever()
""")

sandbox.commands.run("python3 /home/user/server.py", background=True)

# Get the public URL
hostname = sandbox.get_hostname(3000)
print(f"API available at: https://{hostname}")

# You can now access the sandbox service
response = requests.get(f"https://{hostname}")
print(response.json())  # {"status": "ok"}

Working with Ports

Sandboxes can listen on any port. Use getHostname(port) to get the publicly accessible URL for a specific port.

import { Sandbox } from 'vibengine'

const sandbox = await Sandbox.create()

// Different services on different ports
const webHostname = sandbox.getHostname(3000)    // Web app
const apiHostname = sandbox.getHostname(8080)    // API server
const dbHostname = sandbox.getHostname(5432)     // Database

console.log(`Web: https://${webHostname}`)
console.log(`API: https://${apiHostname}`)
console.log(`DB:  https://${dbHostname}`)
from vibengine import Sandbox

sandbox = Sandbox.create()

# Different services on different ports
web_hostname = sandbox.get_hostname(3000)    # Web app
api_hostname = sandbox.get_hostname(8080)    # API server
db_hostname = sandbox.get_hostname(5432)     # Database

print(f"Web: https://{web_hostname}")
print(f"API: https://{api_hostname}")
print(f"DB:  https://{db_hostname}")

Downloading Files from the Web

Use standard tools like curl, wget, or language-level HTTP clients to download files.

import { Sandbox } from 'vibengine'

const sandbox = await Sandbox.create()

// Download a file using curl
await sandbox.commands.run('curl -o /home/user/data.json https://api.example.com/data')

// Download using wget
await sandbox.commands.run('wget -O /home/user/archive.tar.gz https://example.com/archive.tar.gz')

// Read the downloaded file
const content = await sandbox.files.read('/home/user/data.json')
console.log(content)
from vibengine import Sandbox

sandbox = Sandbox.create()

# Download a file using curl
sandbox.commands.run("curl -o /home/user/data.json https://api.example.com/data")

# Download using wget
sandbox.commands.run("wget -O /home/user/archive.tar.gz https://example.com/archive.tar.gz")

# Read the downloaded file
content = sandbox.files.read("/home/user/data.json")
print(content)

While sandboxes have full internet access, be mindful of what external services your sandbox code communicates with. Treat sandbox network access with the same security considerations as any server-side code.

Next Steps

On this page