v0.7.2

Sandbox URL

Expose internal sandbox ports to the internet via unique public URLs with automatic HTTPS.

Publish Parameters

Expose a sandbox port and get a public URL.

portintrequired

The port number to expose (1-65535)

Returns

urlstr

The public HTTPS URL where the port is accessible

url = sbx.network.publish(3000)

Unpublish Parameters

Remove public access to a previously exposed port.

portintrequired

The port number to unpublish

Returns

successbool

True if successful, False if port was not published

success = sbx.network.unpublish(3000)

Published ports are automatically unpublished when the sandbox is deleted.

Basic Usage

Start a server and expose it to the internet:

from concave import sandbox # Create sandbox and start a simple HTTP server (port 3000) with sandbox() as sbx: # Write a small HTTP server that returns "It works!" sbx.execute("""cat > /tmp/server.py << 'EOF' from http.server import HTTPServer, BaseHTTPRequestHandler class HelloHandler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header('Content-Type', 'text/html') self.end_headers() self.wfile.write(b'<h1>It works!</h1>') def log_message(self, format, *args): pass # Suppress logs HTTPServer(('0.0.0.0', 3000), HelloHandler).serve_forever() EOF""") # Start the server in background sbx.execute("python3 /tmp/server.py > /tmp/server.log 2>&1 &") # Publish the port url = sbx.network.publish(3000) print(f"Public URL: {url}")

Examples

Running MCP Server Inside the Sandbox

from concave import sandbox with sandbox() as sbx: # Start MCP server in background sbx.execute("python mcp_server.py &") # Expose the MCP server on port 8080 url = sbx.network.publish(8080) print(f"MCP server accessible at: {url}")

Multiple Ports

from concave import Sandbox sbx = Sandbox.create() # Start multiple services sbx.execute("python /app/api.py") # Port 3000 sbx.execute("python /app/webhook.py") # Port 4000 sbx.execute("python /app/admin.py") # Port 5000 # Expose all ports api_url = sbx.network.publish(3000) webhook_url = sbx.network.publish(4000) admin_url = sbx.network.publish(5000) print(f"API: {api_url}") print(f"Webhook: {webhook_url}") print(f"Admin: {admin_url}")

Running a Web Server

from concave import Sandbox sbx = Sandbox.create() # Start nginx sbx.execute("systemctl enable nginx") sbx.execute("systemctl start nginx") # Expose nginx on port 80 url = sbx.network.publish(80) print(f"Nginx accessible at: {url}")

Exceptions

SandboxValidationErrorException

Raised when the port number is invalid (not in range 1-65535).

SandboxServerErrorException

Raised when there's an issue with the expose-proxy service or URL generation.

SandboxNotFoundErrorException

Raised when the sandbox no longer exists.

Error Handling

from concave import ( Sandbox, SandboxValidationError, SandboxServerError, SandboxNotFoundError ) sbx = Sandbox.create() try: # Start a web server sbx.execute("python3 -m http.server 3000 &") # Publish the port url = sbx.network.publish(3000) print(f"Server accessible at: {url}") except SandboxValidationError as e: print(f"Invalid port: {e}") except SandboxServerError as e: print(f"Service error: {e}") except SandboxNotFoundError as e: print(f"Sandbox not found: {e}") finally: sbx.delete()